I want to make a LaunchBar script that displays in a dialog the path of a file or folder that's chosen in the first pane and then "dropped" on a script. But I can't make it work.

I've got a couple of working scripts that almost do what I want:

Return contents of first pane (used with a shortcut):

tell application "LaunchBar"
   set x to selection as text
   return x
end tell

Display text written in the first pane and "dropped" on the script:

on handle_string(textFromLaunchbar)
   tell application "LaunchBar"
       display in large type textFromLaunchbar
   end tell
end handle_string

The latter uses the handle_string() handler but I can't quite make the open() handler work for files and folders:

from the LaunchBar manual:


Sending items to AppleScripts

To pass a selected file, URL or text to an AppleScript, press the Tab key to trigger the “Send to…” action, select the desired AppleScript and press Return. Files will be passed to the script’s open() handler, URLs will be passed to the handle_string() handler.

  • 2
    Are you trying to use the path in another application? If so, Cmd-C on the file in LaunchBar will put the POSIX path to the file on the clipboard, no need for AppleScript. – Ian C. Feb 27 '12 at 18:17
  • no, but that's a very useful little trick – user19358 Feb 28 '12 at 0:16

The open() handler gets passed an alias (which is a kind of a pointer to a file or folder). You can then simply convert the alias to text, but it will show you the path with colons as separators (e.g. "Macintosh HD:Users:Username:Documents:Folder:").

Use POSIX path of to convert it to a UNIX-style path with "/" separators, and if you want to paste it into Terminal, especially if the path has spaces in it, you should use quoted form of to properly enclose it in quotes.

The following script works with both folders and files for me, when an item is passed to it via LaunchBar:

on open (thisItem)
    display dialog (thisItem as text) -- alias
    display dialog quoted form of POSIX path of thisItem -- POSIX path
end open

I see you know about LaunchBar's "large type" feature -- did you know you can send selected text to it with the "Display in Large Type" action? I.e.

  1. Select your file in LaunchBar
  2. Tab, "dla", return

You must log in to answer this question.