Run an AppleScript on mount?

jbljbl
Posted:
in Genius Bar edited January 2014
Is it possible to set up an AppleScript to run whenever a particular disk is mounted (or unmounted)? How do I do this?

Comments

  • Reply 1 of 5
    I'm not aware of a trigger to launch a script on mounting a volume.



    If you are looking for a specifically named volume (or one of a group of names) you could write a script that periodically checks for the volume. Use the idle handler so the script only runs once every n seconds. This way it doesn't tie up the system just continuously checking for the volume in question.
  • Reply 2 of 5
    jbljbl Posts: 555member
    I guess that would work. Thanks.



    Meanwhile, I think I will suggest this to Apple.
  • Reply 3 of 5
    If you have control over the volume (ie, it's a disk image, or a CD you can burn, or modify and re-burn) then there is a solution.



    Jaguar reintroduced Folder Actions, which run an applescript whenever you open, add to, or remove from a given folder.



    So just:

    * enable Folder Actions (from the Applescript menu item)

    *write a script that does what you want

    *put the script in /Library/Scripts/

    *attach the folder action

    *save the disk image, or burn the CD



    no guarantee but i tried something like it a few months ago and it seemed to work fine.



    Note that as a security feature, the Applescript must be in your local Scripts folder; it can't be on the disk itself, since that could lead to Autostart worms.
  • Reply 4 of 5
    jbljbl Posts: 555member
    [quote]Originally posted by mithras the prophet:

    <strong>If you have control over the volume (ie, it's a disk image, or a CD you can burn, or modify and re-burn) then there is a solution.



    Jaguar reintroduced Folder Actions, which run an applescript whenever you open, add to, or remove from a given folder.



    So just:

    * enable Folder Actions (from the Applescript menu item)

    *write a script that does what you want

    *put the script in /Library/Scripts/

    *attach the folder action

    *save the disk image, or burn the CD



    no guarantee but i tried something like it a few months ago and it seemed to work fine.



    Note that as a security feature, the Applescript must be in your local Scripts folder; it can't be on the disk itself, since that could lead to Autostart worms.</strong><hr></blockquote>



    Sorry, I guess I don't understand this. What would I attach the action to?



    Here is more precisely what I am doing:

    I have a portable FireWire drive with most of my files etc. on it. I take it back and forth to work with me so that I have all of my files at both home and work (and so all my personal mail etc is not on my work machine so if they fire me for downloading mp3s at work, at least I get the mp3s

    )



    I would like to set it up so that, when I get to work

    1) it synchronizes my work files

    2) my iPhoto library and iTunes library are set to aliases which point to the libraries on my FireWire drive.

    Then when I leave work I need it to synchronize again and remove the aliases.



    Could I attach the script to /Volumes? How would I do that and would it be asking for trouble?
  • Reply 5 of 5
    Probably the easiest thing to do is just create this script and save it as an application on your desktop. After your drive mounts double click the application-script. Before leaving run a second script as you describe.
Sign In or Register to comment.