Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to automatically invoke a given applescript when closing -any- file with a given extension in a specified folder (and subfolders)?

If not in AS, is this possible in bash? (The AS I am considering simply calls a bash script.)

share|improve this question

1 Answer 1

If the script could also be run when you open a file (or in other cases), you could use opensnoop.

~/test:

#!/bin/bash

while :; do
    opensnoop | grep -Ev ' (mdworker|mds|filecoordinatio|revisiond|Finder|Alfred) ' | grep -m1 '/Users/username/Folder/.*\.txt'
    say a
    sleep 1
done

/Library/LaunchAgents/test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>test</string>
    <key>Program</key>
    <string>/Users/username/test</string>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

chmod +x ~/test, sudo chown root /Library/LaunchAgents/test.plist, and launchctl load /Library/LaunchAgents/test.plist.

share|improve this answer
    
Thanks -- but unfortunately, this script is only to be run on file close. –  humanengr Jan 21 '13 at 18:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.