使用 apple script 實現逐行貼上的功能
前言
一直以來有這樣一個需求在我腦海裡徘徊,然而我沒有去深究,今天忍不住還是給它實現掉吧。
枯燥的事兒
是這樣的,在做開發的時候,特別是測試功能的時候,比如重複註冊很多個使用者賬號,經常需要重複複製->貼上->提交->再複製->再貼上->再提交
,期間還涉及多個頁面切換去複製文字,真是讓人非常煩躁。
讓複雜的事簡單化
換個思路,這事兒可以這麼解決:一次性複製大量的文字,然後一次貼上只取文字中的一行
。
這樣豈不是完美了。
指令碼程式碼
話不多說,直接上 apple script 程式碼:
set oldClipText to (the clipboard as text) set theList to paragraphs of oldClipText if (count of theList) = 0 then return end if set s to the item 1 of theList set the clipboard to s delay 0.1 tell application "System Events" to keystroke "v" using command down delay 0.1 if (count of theList) > 1 then set theList2 to text (paragraph 2) thru -1 of oldClipText set newClipText to theList2 as string else set newClipText to "" end if set the clipboard to newClipText
簡單的說,就是操作剪下板中的文字,每次呼叫指令碼只粘一行,然後剩下的文字繼續放回剪下板。
後語
配合神器better touch tool
,將上述指令碼繫結成快捷鍵,比如FN + v
,即可實現一次複製大量文字,每次貼上只粘一行
,酷吧:)