Using launchd with AppleScript to Access a Flash Drive Automatically..

FROM THREAD: http://macscripter.net/viewtopic.php?id=24748

I found the above great thread and I am trying to run this script and I get the following error message.

Syntax Erro Expected end of line, etc. but found a real number

I thought adding a “Tell Application Finder” would do it but id doesn’t. Can someone tell me why ?

With regards!
Daniel

"

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http:// [url=http://www.apple.com/DTDs/PropertyList-1.0.dtd"]]www.apple.com/DTDs/PropertyList-1.0.dtd"][/url] <plist version="1.0"]
<key>Disabled</key>
<true/>
<key>Label</key>
<string>WatchingVolumesPath</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
    <string>osascript</string>
    <string>/Users/casdvm/Desktop/AutoFlash.scpt</string>
</array>
<key>ServiceDescription</key>
<string>Runs Applescript directly when Volumes Path changes</string>
<key>StandardOutPath</key>
<string>/Users/casdvm/Desktop/AutoFlashLog.txt</string>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
"

Hi,

you posted the content of the property list file in ~/Library/LaunchAgents,
but the error occurred in the triggered script.

Hello Stefan,

Thanks for your reply. Unfortunately, I am in a position where I do not understand what this code is doing.

I’ve thought the code is used to create a plist file with “Key”, “Type”, “Value”…

At this moment nothing is happening, I’ve added the code in the AppleScript editor. When I click the compile button nothing happen, I only get the error message which tells me there are elements that I am missing to run this code as AppleScript program.

I am sorry, unfortunately I am lost.

At this moment I am using the application “Do Something When”. This application has been good to me, however I require something more personalized.

I do have many Access Flash Drive which all have a name started with the prefix “PZV” followed by a number. For example : PZV0001, PZV0002, PZV0003…

I need to perform some actions when a flash drive starting with “PZV” is mounted on my computer. The number 0001, 0002, 0003 correspond to an order number for which I would perform some operations.

When I read the information found in the thread http://macscripter.net/viewtopic.php?id=24748 I thought this is what I needed. Am I right to think this thread would be helpful to me?

Best regards!

Daniel

Yes, launchd can do what you’re looking for
The code is not AppleScript source code, it’s a property list.
Put the code in a TextEdit and save it with UTF8 encoding in ~/Library/LaunchAgents/WatchingVolumesPath.plist
Omit these two lines, because the launchctl -w command doesn’t set the disabled key to false automatically since 10.6
Disabled

then load the agent in Terminal with

launchctl load -w ~/Library/LaunchAgents/WatchingVolumesPath.plist

In the Applescript you need a property flashState and the handling of the property for each drive

Sorry to go off topic. Can anyone recommend a book that details this process? I see the original thread references Unix for Mac OS X 10.4 Tiger but I can’t find an updated version for a more recent OS. Thanks.