«Как лучше всего объединить этот яблочный скрипт в одну строку?»
Использовать 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"