如何检测是否使用 AppleScript 选择了某些内容?

How can I detect whether something is selected with AppleScript?

我正在使用一种名为 controllermate 的软件,它允许您自定义键盘或鼠标按钮的行为。您可以在 Apple 脚本的特定函数中使用 'building blocks' 之一。我想为我的鼠标创建一个自定义行为,这样如果当前选择了可以复制的内容,某个按钮将执行 CMD+C,否则将执行不同的键盘快捷键。看来我将不得不使用 appleScript 来确定是否选择了文本,但是在在线阅读了其他人的解决方案之后,我无法弄清楚如何自己实现它。谢谢你的帮助。

这是一个解决方案:

将空字符串放入剪贴板,执行CMD+C,检查剪贴板。

set the clipboard to ""
tell application "System Events" to keystroke "c" using command down
delay 0.2

set b to false
try
    set b to (the clipboard as string) is not ""
on error -- error when the clipboard contains a custom type (like a copy in the Photos Application)
    set b to true
end try
if b then -- the clipboard does not contains an empty string
    -- *** script to execute a different keyboard shortcut ***
    --tell application "System Events" to keystroke someChar using someModifier
end if