0

I have an applet i made using Applescript which opens an Application and then once it's loaded runs a shell script which unload's Spotlight. I need to make it then wait for me to finish using relevant Application before running another shell script to load Spotlight again.

My code currently looks like:

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is running    
        delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
    end if
activate appname

I have tried everything but can not figure it out. I found and modified this script with my limited knowledge but do not understand how it works

What code do i need to add to make it wait for me to then quit the application to run the second shell script which i know is:

do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges

which would reload Spotlight?

I came with up the following which compiles but doesn't do as expected:

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is running    
        delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
    end if
activate appname
    repeat until application appname is not running
    delay 1
    end repeat
if application is not running then
    do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
end if

Gives me the error Can't get running of application. I can see something is missing just do not know what.

I'm new to both Apple and Applescript and an answer will be much appreciated.

  • @Danny - I wrote the above code with your suggestion of inserting the not but it doesn't do as expected as explained in my re-edited question above. I hope my edit helps explain my question better. Any suggestions would be much appreciated. Kind regards – Ambush Jan 16 '15 at 11:11
1

you want to test for not running

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is not running    
            delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
end if
activate appname
|improve this answer|||||
  • Perhaps my question was ambiguous. I want to add something to the existing script, so that once I'm done using the Application and i close it, another shell script is run. Basically, I want to run Cubase 5, then unload Spotlight, then once i'm done working in Cubase and quit, have the script load spotlight again. Hope that clarifies.Thanks for the response @Danny – Ambush Jan 13 '15 at 15:50
  • @Ambush - look carefully - I added ONE word to your existing script and now it should behave as you explain. appname is not running – Danny Schoemann Jan 14 '15 at 7:24
  • I saw that you added the not but i don't understand how that will make the script perform all 3 actions? Shouldn't I be adding more code somewhere? – Ambush Jan 16 '15 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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