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

Macos Applescript:检查活动查找器窗口路径是否包含特定名称以更改变量,macos,path,applescript,finder,Macos,Path,Applescript,Finder,我需要一个脚本,查看当前活动的finder窗口路径,并检查pahth是否包含名称。如果找到某个名称,则应将另一个变量更改为其他名称 告诉应用程序“查找器” 将currentDirectory设置为查找器窗口1的目标 结束语 将myVar设置为“something” 将myVar2设置为“xxx” 如果currentDirectory包含myVar,请将myVar2设置为“其他内容”请尝试此代码,并告诉我它是否适用于您: set myVar1 to "Users" set myVar2 to "2

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

告诉应用程序“查找器” 将currentDirectory设置为查找器窗口1的目标 结束语 将myVar设置为“something” 将myVar2设置为“xxx”


如果currentDirectory包含myVar,请将myVar2设置为“其他内容”

请尝试此代码,并告诉我它是否适用于您:

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

请尝试此代码,并让我知道它是否适用于您:

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