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.

Ambush
  • 1

1 Answers1

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
Danny Schoemann
  • 237
  • 3
  • 13