KevinCork KevinCork - 4 months ago 17
AppleScript Question

Applescript if contains a word

Here is my script :

set APPS to { "facebook", "Minecraft"}
if appName contains APPS then
display notification "app founds" with title "Apps"


I also try with

if appName is in APPS then


but in this example, if the app found is "Minecraft: Story Mode" then the script will fail (won't detect anything) how can I make the script to detect this ?

Kind regards

Answer

If you want to check if an item in a collection contains a substring you need a repeat loop

set APPS to {"facebook", "Minecraft"}
repeat with anApp in APPS
    if appName is in anApp then -- or anApp is in appName depending on which is the substring
        display notification "app founds" with title anApp
        exit repeat
    end if
end repeat