Skip to content

Instantly share code, notes, and snippets.

@thedward
Last active January 10, 2017 21:27
Show Gist options
  • Save thedward/7da5e7a89bf665bdd5597f5810c3b5b6 to your computer and use it in GitHub Desktop.
Save thedward/7da5e7a89bf665bdd5597f5810c3b5b6 to your computer and use it in GitHub Desktop.
My notes about the abomination that is AppleScript

Running a Script from within Another Script

source: https://discussions.apple.com/thread/1485146

To run another script file:

run script "HD:path:to:file.scpt"

You can use POSIX file to coerce a Unix path into a Mac path/alias — see the next section.


Working with Paths in AppleScript

source: http://www.satimage.fr/software/en/smile/external_codes/file_paths.html

Where POSIX uses the slash / as the separator for directories, AppleScript uses the colon :.

You can use colon : in a POSIX file name, and you can use slash / in an AppleScript file name: they translate one into the other.

To translate a UNIX path (file or directory, valid or not) into an AppleScript file reference, use POSIX file. POSIX file returns a file reference, that your script can use directly to create or use the file.

set p to "/usr/local/bin/" 
set a to POSIX file p 
   *-- file "Macintosh HD:usr:local:bin:"*

To translate an AppleScript path (file or directory, valid or not) into a POSIX path use POSIX path of.

set a to "Macintosh HD:usr:local:bin:" 
set p to POSIX path of a 
   *-- "/usr/local/bin/"*

POSIX path also understands AppleScript's file references.

set a to alias "Macintosh HD:usr:local:bin:" 
set p to POSIX path of a 
   *-- "/usr/local/bin/"* 
set a to file "Macintosh HD:usr:local:bin:" 
set p to POSIX path of a 
   *-- "/usr/local/bin/"*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment