Is it possible to run an applescript automatically when something in System Events happens. More specifically, I want to run a script when my iPod is connected and when it is disconnected, without me worrying about it. If so an example would really help.
I don’t have an iPod but I assume when you attach it it appears as a volume? If so, you can detect a newly mounted volume by means of a folder action using the Folder Actions Setup app, associating it with the /Volumes directory. The folder action might look like
on adding folder items to thisFldr after receiving theseVolumes
set itm to item 1 of theseVolumes
tell application "Finder" to set n to name of itm
display dialog "Herzliche Willkommen " & n & "!"
end adding folder items to
This just displays the name of the volume mounted but you can substitute whatever code you want. “on removing folder items from thisFolder after losing…” should work for the disconnect.
If this works, could you please send me an iPod in repayment?
on adding folder items to thisFldr after receiving theseVolumes
set itm to item 1 of theseVolumes
tell application "Finder" to set n to name of itm
if n = "insert name of iPod here" then
run script file "/Users/benpalmer/Library/iTunes/scripts/Shuffle1.scpt"
end if
end adding folder items to