[MacTUG] Applescript drag and drop!

Donald Duff-McCracken dsmccrac at uwaterloo.ca
Fri Sep 23 14:03:51 EDT 2016


I still use applescript more than Automator. Frankly most of the time I just it to run shell scripts and do cool things with the results.

Recently I discovered something by accident! Much like how you can drag a file or directory onto the terminal window (and save having to type the path to said file or directory), you can do the same in Applescript’s Script Editor App!

Speaking of running shell commands in applescript, I am glad to know that it sends a OSIX friendly path “/” vs “:” but you may need to massage the path depending on what you want to do with it

For example, while it is using slashes instead of colons in the path, it is still not dealing with the spaces in pathnames. This can be handled by using the “quoted from of” modifier. For example, this works

tell application "Finder"
      set DirContents to (do shell script "ls " & quoted form of "/Volumes/users$/dsmccrac/ERS375_Preferences/Presets/Export Presets")

      -- result is "ERS 375 Print.lrtemplate"
end tell

If you are needing the path described in the conventional way applescript uses ( colons instead of slashes), using the POSIX file modifier does the trick.

tell application "Finder"
      open POSIX file "/Volumes/users$/dsmccrac/ERS375_Preferences/Presets/Export Presets"

      -- result is the “Export Presets” folder is opened
end tell

Thus ends my Friday afternoon sharing about a programing language that really has not changed much in the last 20 years haha
------------------------------------
Donald Duff-McCracken
Technical Services Manager
Mapping, Analysis & Design
Faculty of Environment
University of Waterloo
(519) 888-4567 x32151
https://uwaterloo.ca/environment-computing/about/people
------------------------------------
This email communication is intended as a private communication for the sole use of the primary addressee and those individuals listed for copies in the original message. The information contained in this email is private and confidential and If you are not an intended recipient you are hereby notified that copying, forwarding or other dissemination or distribution of this communication by any means is prohibited.  If you are not specifically authorized to receive this email and if you believe that you received it in error please notify the original sender immediately.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uwaterloo.ca/pipermail/mactug/attachments/20160923/b0902f07/attachment.html>


More information about the MacTUG mailing list