System Events & Applescripts

Hello,

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.

Thanks.

ben p

I don’t have an iPod :cry: 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? :stuck_out_tongue:

  • Dan

So I think im about 1/2 way there…

First, do I change “theseVolumes” with the name of my iPod?

Second, if I want to add a line that tell the computer to run a script when the iPod is attached, will it look like this…

tell application "Finder" to execute / Users / benpalmer / Library / iTunes / scripts / Shuffle1.scpt

Thanks again.

Ben

More 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
	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

I think that should do it…if not, let me know.

  • Dan