Applescript Question.

Posted:
in Genius Bar edited January 2014
Hey Guys and Gals.



I think that I can do this using AppleScript(s) but not sure how.



When I plug my usb key drive, I want it to automatically copy a few items over, like a few files I work on almost everyday.



Any suggestions on the best way to do this?



cheers



J-E-O

Comments

  • Reply 1 of 6
    karl kuehnkarl kuehn Posts: 756member
    As far as I can tell Apple explicitly got rid of autostart functions as a security risk with a now-ancient version of QuickTime, and has never gone back. So there is no easy way of getting an applescript to trigger on insert.



    The only solutions would be to create a daemon process that would watch /Volumes for the device to show up, or play with the kext that serves as the driver for USB disk devices and put in a hook... not a trivial exercise.



    My best advice would be to create an AppleScript or ".command" shell script that does what you want and manually trigger it. If you decide to go with the .command, I would advise looking into rsync.
  • Reply 2 of 6
    Hey Karl your becoming my one man answer shop lol



    Cheers, it's a bummer that i can't do it. I thought there might be something like watch folder typething.



    Ill look into rsync.



    thanks
  • Reply 3 of 6
    gongon Posts: 2,437member
    It doesn't sound like an execution hook for USB key insert would be a security problem, as long as the script that runs, was installed on the computer and nothing is auto-run from the USB key.. or did I miss something?



    (I don't know AppleScript so this is not specifically about that)
  • Reply 4 of 6
    durandaldurandal Posts: 277member
    Quote:

    Originally posted by jon-e-orange

    Hey Karl your becoming my one man answer shop lol



    Cheers, it's a bummer that i can't do it. I thought there might be something like watch folder typething.



    Ill look into rsync.



    thanks




    Hmmm.... what about Folder Actions? If one attached a folder action that is triggered when a new item is added to the /Volumes directory... well, unfortunately I can't test it now, my iBook just went away to Apple (the well-known motherboard bug "ate" it)



    Greetings,

    durandal
  • Reply 5 of 6
    Cheers Durandal! I tested it and it worked.



    I used the new item alert folder action script and as soon as I added an extra drive (i tested with a floppy drive) the alert popped up.



    I can now start work on my script



    the next big thing is to one get the script to work when I use the key drive. I must be able to run only when specific volume name is added.



    thanks
  • Reply 6 of 6
    costiquecostique Posts: 1,084member
    Quote:

    Originally posted by jon-e-orange

    I must be able to run only when specific volume name is added.



    That's easy. Look at scripts located in /Library/Scripts/Folder Action Scripts/ for examples. Basically, for a folder action script you have to add the on adding folder items to this_folder after receiving added_items handler, from which you can access the list of added items (added_items), which in your case is a list of folders, the names of which you should test against your USB drive's volume name.
Sign In or Register to comment.