【问题标题】:Menu Button from AppleScriptAppleScript 中的菜单按钮
【发布时间】:2013-11-24 18:53:51
【问题描述】:

我的 PDF 查看器是 Skim.app,我使用下面的一段 applescript 代码要求它从磁盘重新读取所有打开的文档,我需要让它经常这样做。问题是 Skim.app 有点错误,在很多方面。它的一个错误是,当它重新加载现有文档时,它会有点乱码。幸运的是,一次缩放和一次取消缩放修复了乱码,但必须手动执行非常烦人。

缩放按钮在菜单项“PDF”->“放大”,取消缩放为“PDF”->“缩小”。每次运行时都可以让applescript代码为我进行缩放和取消缩放吗?如果有怎么办?

#!/bin/bash
/usr/bin/osascript << EOF
  set theFile to POSIX file "$1" as alias
  set thePath to POSIX path of theFile
  tell application "Skim"
    activate
    set theDocs to get documents whose path is thePath
    try
      if (count of theDocs) > 0 then revert theDocs
    end try
    open theFile
  end tell
EOF

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    您可以使用系统事件来单击菜单项。您还可以通过添加显式运行处理程序来传递参数。

    #!/usr/bin/osascript
    
    on run argv
        tell application "Skim"
            activate
            revert (documents where path is item 1 of argv)
            open POSIX file (item 1 of argv) as alias
        end tell
        tell application "System Events" to tell process "Skim"
            click menu item "Zoom In" of menu 1 of menu bar item "PDF" of menu bar 1
            click menu item "Zoom Out" of menu 1 of menu bar item "PDF" of menu bar 1
        end tell
    end run
    

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 2012-07-07
      • 1970-01-01
      • 2013-03-11
      • 2017-05-21
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      相关资源
      最近更新 更多