2017-09-11 60 views
1

我使用一些名爲controllermate的軟件,允許您自定義鍵盤或鼠標上按鈕的行爲。可以在蘋果腳本的特定功能中使用的「構建塊」之一。我想爲我的鼠標創建一個自定義行爲,以便某些按鈕將執行CMD + C,如果當前選擇了可以複製的內容,但執行其他鍵盤快捷方式。看來我將不得不使用一個appleScript來確定是否選擇了文本,但在閱讀了其他一些其他人的解決方案後,我無法弄清楚如何自己實現它。謝謝你的幫助。如何檢測AppleScript是否選擇了某些內容?

回答

0

這裏有一個解決方案:

把一個空字符串到剪貼板,做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 
相關問題