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.

Does any one of you know if it's possible to call a script right after opening a file.

For example : I want to relocate QuickTime in the top-left corner right next to my dock.

I know how to do it with AppleScript (the location thing) but how can I call this script automatically ?

share|improve this question

2 Answers 2

This is a bit of a hack, but try watching for changes to some file that is modified when the application opens a document.

Using launchd, you could save this as ~/Library/LaunchAgents/test.plist and run launchctl load ~/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>ProgramArguments</key>
    <array> 
        <string>osascript</string>
        <string>-e</string>
        <string>try
tell app "System Events" to tell process "QuickTime Player"
set position of window 1 to {500, 500}
end
end</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Users/username/Library/Preferences/com.apple.QuickTimePlayerX.LSSharedFileList.plist</string>
    </array>
</dict>
</plist>

It won't work if you open multiple documents in a row, because launchd runs programs only at most every 10 seconds.

share|improve this answer
    
Yep it works but after 10 sec. But not very practical. –  Matthieu Riegler Jan 14 '13 at 18:09

Have you tried this?

Do Something When - Project

It seems like what you want...I have never personally used it.

share|improve this answer

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.