将变量传递给applescript中的处理程序(函数)

将变量传递给applescript中的处理程序(函数),applescript,Applescript,test\u two()和test\u three work(),但test\u one()不起作用。为什么呢?如何将参数传递到处理程序并将其用作局部变量 set the_application to "Safari" test_one(the_application) on test_one(the_application) tell application the_application make new document with propert

test\u two()
test\u three work()
,但
test\u one()
不起作用。为什么呢?如何将参数传递到处理程序并将其用作局部变量

set the_application to "Safari"
test_one(the_application)
on test_one(the_application)
    tell application the_application
        make new document with properties {URL:"http://www.stackoverflow.com"}
    end tell
end test_one
# ----

test_two()
on test_two()
    tell application "Safari"
        make new document with properties {URL:"http://www.stackoverflow.com"}
    end tell
end test_two
# ----

set the_application to "Safari"
test_three(the_application)
on test_three(the_application)
    tell application the_application
        activate
    end tell
end test_three


当您想使用多个应用程序通用的一些术语时,您可以使用其中一个术语。此条款也适用于其他应用程序。您可以在代码的第一行中指明任何应用程序的名称,该应用程序具有命令使用属性创建新文档和属性URL

set the_application to "some Safari like application"
test_one(the_application)

on test_one(the_application)
    using terms from application "Safari"
        tell application the_application
            make new document with properties {URL:"http://www.stackoverflow.com"}
        end tell
    end using terms from
end test_one
其他示例(在桌面上创建新文件夹):


当您想使用多个应用程序通用的一些术语时,您可以使用其中一个术语。此条款也适用于其他应用程序。您可以在代码的第一行中指明任何应用程序的名称,该应用程序具有命令使用属性创建新文档和属性URL

set the_application to "some Safari like application"
test_one(the_application)

on test_one(the_application)
    using terms from application "Safari"
        tell application the_application
            make new document with properties {URL:"http://www.stackoverflow.com"}
        end tell
    end using terms from
end test_one
其他示例(在桌面上创建新文件夹):


这是我的另一个工作解决方案,可能比我的第一个更好:

set the_application to "Safari"
test_one(the_application)

on test_one(the_application)
    set theScript to "tell application \"" & the_application & "\"
make new document with properties {URL:\"http://www.stackoverflow.com\"}
    end tell"
    run script theScript
end test_one

这是我的另一个工作解决方案,可能比我的第一个更好:

set the_application to "Safari"
test_one(the_application)

on test_one(the_application)
    set theScript to "tell application \"" & the_application & "\"
make new document with properties {URL:\"http://www.stackoverflow.com\"}
    end tell"
    run script theScript
end test_one

这回答了你的问题吗?我不这么认为。在测试三中,我没有在“tell application”语句中使用字符串文字作为参数,它工作得很好。因为
activate
是每个应用程序都响应的全局命令,即使它没有AppleScript dictionary.Hmm。因此,有时我可以在“tell application”语句中使用变量,有时不可以,这取决于我在tell块中使用的操作?所以
activate
是一个全局命令,而
make
是一个…本地命令?有这些东西的清单吗?我没有找到关于applescript的很好的文档。而且,只有
告诉应用程序
有这个问题吗?这是否回答了您的问题?我不这么认为。在测试三中,我没有在“tell application”语句中使用字符串文字作为参数,它工作得很好。因为
activate
是每个应用程序都响应的全局命令,即使它没有AppleScript dictionary.Hmm。因此,有时我可以在“tell application”语句中使用变量,有时不可以,这取决于我在tell块中使用的操作?所以
activate
是一个全局命令,而
make
是一个…本地命令?有这些东西的清单吗?我在applescript上找不到很好的文档。而且,只有
告诉应用程序
有这个问题吗?请注意,除了标准套件中的一些基本术语外,在不同应用程序之间成功使用术语和事件代码完全是偶然的/巧合的,由于开发人员可以随心所欲地定义这些项(没有标准的命名约定)。请注意,除了标准套件中的一些基本术语外,在不同应用程序之间成功使用术语和事件代码完全是偶然的/巧合的,因为开发人员可以随心所欲地定义这些项(没有标准的命名约定)。