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

后端 未结 6 716
眼角桃花
眼角桃花 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条回答
  •  旧时难觅i
    2020-11-30 20:46

    Some Info:

    "Enhanced Application Object Model":

    tell application "iTunes"
        if it is running then
          pause
        end if
    end tell
    

    You can also do it that way:

    if application "iTunes" is running then
        tell application "iTunes" to quit
    end if
    

    You can also do this:

    get name of application "iTunes"
    get version of application "iTunes"
    

    And to complete the journey:

    get id of application "TextEdit" --> "com.apple.TextEdit"
    tell application id "com.apple.TextEdit"
        make new document
    end tell
    

    That was the "Enhanced Application Object Model". If an app still launches (for example, the first time you compile & execute the script) I assume it is because AS has to get some info from the app which it did not found in the dictionary (or something like that...?).

提交回复
热议问题