Apple Automator 截屏并保存到用户指定的位置

Apple Automator take screen capture and save to user-specified location

因此,我正在尝试使用 Mac OS Yosemite 下的 Automator 创建一项服务,以允许用户截取屏幕截图并将其保存到他们指定的位置,通过某种 "Save As" 对话框。看起来应该很容易,但出于某种原因,我 运行 遇到了困难。屏幕截图组件很简单,使用 Automator 中的 "Take Screenshot" 操作,但将其保存到自定义位置导致我遇到问题。

尝试了几种不同的方法后,最简单的方法似乎是在 "Take Screenshot" 操作中将屏幕截图保存到固定的 directory/filename,然后(使用 AppleScript)重命名它在该目录中,并将其移动到用户指定的目标目录。因此,我向我的服务添加了一个 "Run AppleScript" 操作。在其中,我使用 AppleScript 中的 choose file name 命令生成对话框以选择文件 name/path。我正在尝试从路径中拆分文件名,以便我可以重命名我保存在 "Take Screenshot," 中的文件,然后将其移动到我想要保存它的路径。我可以获得完整路径,但在从路径中获取文件名时遇到了问题——我已经尝试了我在网上看到的各种建议。在我的屏幕截图中,显示的错误是尝试执行

我对这个流程没有任何准备,所以如果有人对如何做我想做的事情有更好的建议,请务必告诉我。否则,如果有人能够告诉我如何从路径中提取文件名(并且如果有一些特殊的方法你必须使用该字符串重命名文件)那就太好了!

截图中的 AppleScript 代码:

on run {parameters}
    set thePath to (choose file name with prompt "Where would you like to save your file?")
    tell application "Finder"
        display dialog thePath as string
    end tell
    set UnixPath to POSIX path of (thePath as text)
    display dialog UnixPath
end run

我试过了,但没用:

set basePath to POSIX path of (parent of (thePath) as string)

感谢查看!

一个简单的方法是使用命令行工具 "screencapture"。它有很多选项供您选择。请参阅其手册页。这是一个示例,您可以 运行 直接作为 applescript,或者如果需要,您可以将其放入 applescript automator 操作中。

祝你好运。

set thePath to (choose file name with prompt "Where would you like to save your file?")
do shell script "screencapture -mx -T1 " & quoted form of (POSIX path of thePath & ".png")

我在 Automator 中创建了文件夹操作。选择桌面。添加 Find Finder 对象(搜索:桌面)。添加 Move Finder 对象并选择您喜欢的目的地。这将自动移动所有屏幕截图。