Stephan Zwetschke Stephan Zwetschke - 11 months ago 66
AppleScript Question

Applescript: check if active finder window path contains certain name to change a var

I need a script that looks at the current active finder window path and checks if the pahth contains a name. If a certain name is found, then another variable should be changed to something else.

tell application "Finder"
set currentDirectory to target of Finder window 1
end tell
set myVar to "something"
set myVar2 to "xxx"

if currentDirectory contains myVar then set myVar2 to "something else"

oa- oa-
Answer Source

Please try this code and let me know if it works for you:

set myVar1 to "Users"
set myVar2 to "2"
set myVar3 to "3"

tell application "Finder"
    set thePath to (POSIX path of (target of window 1 as alias))
    if thePath contains myVar1 then
        set myVar2 to myVar3
    end if
end tell