How to check in AppleScript if an app is running, without launching it - via osascript utility

后端 未结 6 701
眼角桃花
眼角桃花 2020-11-30 20:11

Consider the following AppleScript:

on is_running(appName)
    tell application \"System Events\" to (name of processes) contains appName
end is_running

set         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 20:43

    tell application "Finder"
        set applicationsnames to get the name of every process whose visible is true
    end tell
    
    set appName to "Safari"
    
    if applicationsnames does not contain appName then
        say (appName & " is not running")
        --add here what you want to happen
    
    end if
    return applicationsnames
    

    This is returning {"Finder", "JavaAppLauncher", "firefox", "Microsoft Word", "iTunes", "AppleScript Editor"} for me

    Hope this helps

提交回复
热议问题