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