【问题标题】:Apple Automator take screen capture and save to user-specified locationApple Automator 截屏并保存到用户指定的位置
【发布时间】:2015-02-11 02:50:03
【问题描述】:

因此,我尝试在 Mac OS Yosemite 下使用 Automator 创建服务,以允许用户通过某种“另存为”对话框截取屏幕截图并将其保存到他们指定的位置。看起来应该很容易,但由于某种原因,我遇到了困难。屏幕截图组件很简单,使用 Automator 中的“截屏”操作,但将其保存到自定义位置给我带来了问题。

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

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

截图中的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)

感谢您查看!

【问题讨论】:

  • 查看 Script-Editor 在其“文件”菜单中的模板,尝试“Droplets => Droplet with settable properties”/它包含显示如何获取文件名称/扩展名的代码小路。此外,在 Terminal.app 窗口中查看“man screencapture”。 “screencapture”完成所有实际工作。

标签: applescript automator


【解决方案1】:

一个简单的方法是使用命令行工具“screencapture”。它有很多选项可供您选择。请参阅其手册页。这是一个示例,您可以直接作为 applescript 运行,也可以根据需要将其放入 applescript automator action。

祝你好运。

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")

【讨论】:

  • 谢谢,效果很好!不知道为什么 Apple 不使用纯 Automator 操作让这更容易,除非我遗漏了什么。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-05
    • 2014-02-07
    • 1970-01-01
    • 2021-06-18
    • 2015-12-05
    • 2019-05-24
    • 1970-01-01
    • 2020-01-16
    相关资源
    最近更新 更多