Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos AppleScript—;按名称字符串获取应用程序_Macos_Applescript - Fatal编程技术网

Macos AppleScript—;按名称字符串获取应用程序

Macos AppleScript—;按名称字符串获取应用程序,macos,applescript,Macos,Applescript,这段代码运行良好 tell application "System Events" set bounds of window "File" of application "TextEdit" to {0, 0, 0, 0} end tell 这个代码不起作用。如何解决这个问题 tell application "System Events" set appName to "TextEdit" set bounds of window "File" of applicat

这段代码运行良好

tell application "System Events"
    set bounds of window "File" of application "TextEdit" to {0, 0, 0, 0}
end tell
这个代码不起作用。如何解决这个问题

tell application "System Events"
    set appName to "TextEdit"
    set bounds of window "File" of application appName to {0, 0, 0, 0}
end tell

你在谈论两件不同的事情

  • 访问可编写脚本的应用程序的元素和属性。
    在这种情况下,不需要
    系统事件
    ,但目标应用程序的名称必须是文本字符串(编译时对术语的评估)

  • 访问应用程序进程的UI元素的元素和属性(可编写脚本或不可编写脚本)。 在这种情况下,您必须使用
    系统事件
    并指定应用程序进程。可以在变量中传递目标进程的名称

    tell application "System Events"
        set appName to "TextEdit"
        tell process appName
           set bounds of window "File" to {0, 0, 0, 0}
        end tell
    end tell
    

  • 在这两种情况下,都不能保证目标应用程序或目标进程具有包含
    bounds
    属性的
    window
    元素。

    您谈论的是两件不同的事情

  • 访问可编写脚本的应用程序的元素和属性。
    在这种情况下,不需要
    系统事件
    ,但目标应用程序的名称必须是文本字符串(编译时对术语的评估)

  • 访问应用程序进程的UI元素的元素和属性(可编写脚本或不可编写脚本)。 在这种情况下,您必须使用
    系统事件
    并指定应用程序进程。可以在变量中传递目标进程的名称

    tell application "System Events"
        set appName to "TextEdit"
        tell process appName
           set bounds of window "File" to {0, 0, 0, 0}
        end tell
    end tell
    
  • 在这两种情况下,都不能保证目标应用程序或目标进程具有包含
    bounds
    属性的
    window
    元素