保存Applescript会删除字符


2

我已经编写了一个Applescript来启动和定位应用程序的两个实例。使用以下代码,脚本可以在编辑器中完美运行:

tell application "App" to activate
tell application "System Events" to tell application process "App"
    set position of window 1 to {8, 22}
end tell
tell application "App 2" to activate
tell application "System Events" to tell application process "App 2"
    set position of window 1 to {914, 22}
end tell

它不是可编写脚本的应用程序,因此我正在使用系统事件(我还更改了第二个应用程序的CFBundleName,以便它包括2以区分进程)。当我运行它时,在编辑器中一切正常。但是,当我将脚本另存为应用程序时,即使我将其保存正常,只要我保存应用程序,它就会始终从“应用程序2”中删除“ 2”。有谁知道为什么会这样吗?我是Applescript的新手。


您的问题没有答案,但是您无需再提供该应用程序的第二份副本即可完成您要实现的目标。看到这里
Vic

Answers:


1

您可以通过在系统事件中动态选择应用程序来避免编译时出现问题。

tell application "System Events"
    set App1 to (first process whose name is "App")
    tell App1
        set frontmost to true
        set position of window 1 to {8, 22}
    end tell
end tell

然后对App2执行相同操作。


0

主要问题是Apple脚本编辑器不知道任何名称“ App”或“ App 2”,因此,如果您运行脚本,它将要求您选择App的存储位置,然后将“ App”替换为“ Apply”。应用程序。“应用程序2”也会发生这种情况。

因此,如果您两次选择相同的应用程序(根据您的提及,这就是您要尝试的操作),那么这两次都将删除名称为“ App”和“ App 2”的名称,且名称与实际应用程序相同。

或者,如果您将App用作应用程序实际名称的缩写,则它会在第一条语句中知道该应用程序,但在第二条语句中却不知道,因此它只会询问一次并仅替换“ App 2”。

要执行您想要的操作,我建议您将脚本更改为类似的内容,然后以这种方式尝试(未测试):

tell application "<Name of Application>" to activate --open first Window
tell application "<Name of Application>" to activate --open second Window

tell application "System Events" to tell application process "<Name of Application>"
    set position of window 1 to {8, 22}
    set position of window 2 to {914, 22}
end tell

如果这不起作用,则可以采用此脚本来并排移动两个打开的Finder Windows。

property monitor_width : 980
property monitor_height : 768

set the startup_disk to (path to startup disk)

tell application "Finder" activate
    set visible of (every process whose visible is true and frontmost is false) to false
    -- BOTTOM WINDOW
    set this_window to make new Finder window
    set the target of this_window to the startup_disk
    set the bounds of this_window to {0, (monitor_height * 0.55) div 1, monitor_width, monitor_height}
    set the current view of this_window to column view
    -- TOP WINDOW
    set this_window to make new Finder window
    set the target of this_window to the startup_disk
    set the bounds of this_window to {0, (monitor_height * 0.06) div 1, monitor_width, (monitor_height * 0.53) div 1}
    set the current view of this_window to column view
end tell

来源:http//hints.macworld.com/article.php?story = 20011127022706921

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.