Applescript:检查活动查找器 window 路径是否包含特定名称以更改变量

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

我需要一个脚本来查看当前活动的查找器 window 路径并检查路径是否包含名称。如果找到某个名称,则应将另一个变量更改为其他名称。

告诉应用程序"Finder" 将 currentDirectory 设置为 Finder 的目标 window 1 结束告诉 将 myVar 设置为 "something" 将 myVar2 设置为 "xxx"

如果 currentDirectory 包含 myVar,则将 myVar2 设置为 "something else"

请试试这个代码,让我知道它是否适合你:

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