AppleScript的菜单按钮

时间:2013-11-24 03:07:57

标签: macos applescript

我的PDF查看器是Skim.app,我使用下面的一些AppleScript代码要求它重新读取磁盘上的所有打开文档,我需要经常这样做。麻烦的是,Skim.app有点儿错误,不止一个。它的一个缺点是,当它重新加载现有文档时,它会稍微惹恼它。幸运的是,缩放一次并且不缩放一次可以修复乱花,但是必须手动操作非常烦人。

缩放按钮位于菜单项“PDF” - > “放大”,unzoom是“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

1 个答案:

答案 0 :(得分:0)

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

#!/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