Put the quoted form of POSIX paths into Script Editor

Aug 29, '08 07:30:00AM

Contributed by: musselrock

As a beginner learning the basics of do shell script in AppleScript, I'm finding that most of my file and folder names have spaces in them. As such, I have two choices when writing paths: either escape all the spaces as I type them, or use the AppleScript quoted form of POSIX path construct.

Both methods still require significant typing and exact spelling, and I'm from the generation that didn't learn to type. To ease my discomfort, I wrote this script for use in Script Menu:

tell application "Finder"
  set Itms to selection
  set als to Itms's item 1 as alias
  set aPath to quoted form of POSIX path of als
end tell

tell application "Script Editor"
  activate
  tell front document
    set contents of selection to aPath
  end tell
end tell
The script takes the currently-selected file or folder in Finder, and puts its quoted form of POSIX path into Script Editor's front document at the insertion point (or replaces the selection if text is selected). If you type as fast a my 12 year old granddaughter, you probably don't need this.

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080826233738852