「このアップルスクリプトを 1 行にまとめる最良の方法は何ですか?」
AppleScript を使用しますか? :-D
まず、AppleScript エディターで [設定] ウィンドウを開き、オプションをクリックしてShow Script menu in menu bar
.
次にOpen Scripts Folder
、画面の右上にあるスクリプト メニュー項目から選択します。
次のスクリプトを使用して、新しい AppleScript .scptd ドキュメントを作成します。
tell application "AppleScript Editor"
set string_ to text of first document
-- make a list with each line of the script
set stringLines to paragraphs of string_
set originalDelims to AppleScript's text item delimiters
-- add newlines
set AppleScript's text item delimiters to "\\n"
-- now combine the items in the list using newlines
set stringNewlines to stringLines as string
set AppleScript's text item delimiters to "\""
set stringNewlines to text items of stringNewlines
set AppleScript's text item delimiters to "\\\""
set stringNewlines to stringNewlines as string
set AppleScript's text item delimiters to originalDelims
set stringNewlines to "@\"" & stringNewlines & "\""
set the clipboard to stringNewlines
end tell
(このスクリプトは完全ではないことに注意してください。提供されたような単純なスクリプトでは問題なく動作しますが、それ自体を変換することはできません)。
それを、前に明らかにした Scripts フォルダーにスクリプトとして保存します。
次に、変換したいスクリプト ドキュメントを開き、AppleScript エディタでフロント ドキュメントにします。次に、[スクリプト] メニューから選択して、変換スクリプトを呼び出します。
あなたが提供したスクリプトを考えると、それは次の定数を生成するはずですNSString
:
@"tell application \"Terminal\"\n activate\n set currentTab to do script \"1\"\n do script \"2\" in currentTab\n do script \"3\" in currentTab\n do script \"4\" in currentTab\n delay 0.5\n tell application \"Finder\" to set visible of process \"Terminal\" to false\nend tell\n"