如何使用 AppleScript 检查粘贴到剪贴板的值
我是一名 AppleScript 菜鸟,我真的很想用它做点好事。如何制作一个始终运行检查剪贴板更改的 AppleScript?我想要做的是检查剪贴板,看看它是否是某个值,然后使用该剪贴板值发出网络请求。
这就是我目前拥有的,它只是获取当前剪贴板中的值
get the clipboard
set the clipboard to "my text"
任何帮助将不胜感激。提前致谢。
I'm an AppleScript noob, and I really want to do something nice with it. How can I make an AppleScript that runs at all times checking for clipboard changes? What I want to do is check the clipboard, see if it's a certain value, and make a web request with that clipboard value.
This is what I currently have, it just gets the value that's in the current clipboard
get the clipboard
set the clipboard to "my text"
Any help will be GREATLY appreciated. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AppleScript 没有办法“等待剪贴板更改”,因此您必须定期“轮询”剪贴板。
重复
循环并暂停有些人可能会使用
do shell script "sleep 5"
而不是delay 5
;我从来没有遇到过延迟问题,但我从未在像这样的长时间运行的程序中使用过它。根据用于运行该程序的启动器,这样的脚本可能“捆绑”应用程序并阻止其启动其他程序(某些启动器一次只能运行一个 AppleScript 程序)。
使用
idle
处理程序的“保持打开”应用程序更好的替代方案是将程序另存为“保持打开”应用程序(在“另存为...”对话框中)并使用 <代码>用于定期工作的空闲处理程序。
AppleScript does not have a way to “wait for the clipboard to change”, so you will have to “poll” the clipboard at regular intervals.
repeat
loop with a pauseSome might use
do shell script "sleep 5"
instead ofdelay 5
; I have never had a problem withdelay
, but I have never use it in a long-running program like this one.Depending on the launcher used to run this program such a script might “tie up” the application and prevent it from launching other programs (some launchers can only run one AppleScript program at a time).
“Stay Open” application with
idle
handlerA better alternative is to save your program as a “Stay Open” application (in the Save As… dialog) and use an
idle
handler for the periodic work.