0

Was wondering if there is any way to run a small piece of apple script when I launch an application on OS X? I have a hard-drive which need to be mounted in order for the app to run right. I did this apple script already:

on run
try

    do shell script "diskutil mountDisk disk2"

    delay 3
    tell application "Application"
        run
    end tell

on error
    tell application "Application"
        quit
    end tell
    set question to display dialog "Error." buttons {"OK"}
    set answer to button returned of question
    if answer is equal to "OK" then
        close
    end if

end try
end run

But even tho this works great and the hard-drive spins up before the app starts. I would like to add the diskutil mountDisk disk2 and delay directly in front of the real application when its starting so I can double click files for that app say in my downloads folder. Which will run the script before it opens the clicked file in the app. So I wont have to start the application with another application each time i download a new file for it. Is this even possible?

Machavity
  • 30,841
  • 27
  • 92
  • 100
fames
  • 46
  • 3
  • You could maybe run `fswatch` (which can be installed with **homebrew**) and monitor the executable binary for your app to see when it is opened and then run your `diskutil mountDisk` command... and hope you get there in time. Something related here https://stackoverflow.com/a/47978505/2836621 – Mark Setchell Mar 01 '18 at 12:03
  • work around I use is to create the applescript which runs diskutil first, then open the application. I remove the app icon from the doc and replace it by the icon of the script. I always click on this script to start both script and application. – pbell Mar 01 '18 at 19:42

1 Answers1

0

Shortly:

It's not possible unless the application itself supports some inhook and outhook functionality.

vadian
  • 274,689
  • 30
  • 353
  • 361