Печать в Stdout с помощью applescript

Я пытаюсь запустить AppleScript script с терминала, однако я не могу заставить его ничего печатать, вызывая

 osascript myFile.scpt "/path/to/a/file"

Я пытаюсь:

on run fileName

set unique_songs to paragraphs of (read POSIX file fileName)

repeat with nextLine in unique_songs
    if length of nextLine is greater than 0 then
        set AppleScript text item delimiters to tab
        set song to text item 2 of nextLine
        set artist to text item 3 of nextLine
        set album to text item 4 of nextLine

        set output to ("Song: " & song & " - " & artist & " - " & album)
        copy output to stdout
    end if
end repeat
end run

Файл с разделителями табуляции отформатирован примерно так:

1282622675  Beneath the Balcony Iron & Wine The Sea & the Rhythm    
1282622410  There Goes the Fear Doves   (500) Days of Summer        
1282622204  Go to Sleep. (Little Man Being Erased.) Radiohead   Hail to the Thief

Вкладки не очень хорошо отображаются на этом: (

Ответы

Ответ 1

Не очень понятно, КАК вы пытаетесь запустить его в Терминале. Но я предполагаю, что вы сохранили текстовый файл applecript с помощью #!/usr/bin/osascript shebang и #!/usr/bin/osascript файл chmod чтобы иметь возможность его выполнить.

Затем вызывается файл в терминале, просто используя путь к файлу.

#!/usr/bin/osascript

#Here be the rest of your code ...

set output to ("Song: " & song & " - " & artist & " - " & album)


    do shell script "echo " & quoted form of output
end tell

Обновление 2, в ответ на комментарии.

Если у меня есть текстовый файл с разделителями табуляции с содержанием как:

track   Skin Deep   Beady Belle Closer

Вкладки настроены так: трек **** TAB **** Skin Deep **** TAB **** Beady Belle **** TAB **** Closer

И файл сценария как:

on run fileName

    set unique_songs to paragraphs of (read POSIX file fileName)

    repeat with nextLine in unique_songs
        if length of nextLine is greater than 0 then
            set AppleScript text item delimiters to tab
            set song to text item 2 of nextLine
            set artist to text item 3 of nextLine
            set album to text item 4 of nextLine

            set output to ("Song: " & song & " - " & artist & " - " & album)
            do shell script "echo " & quoted form of output
        end if
    end repeat

end run

Затем в Терминале запустите:

/usr/bin/osascript ~/Documents/testOsa2.scpt ~/Documents/testTab.txt

Я вернусь:

*Song: Skin Deep - Beady Belle - Closer*

Ответ 2

При запуске AppleScript с #!/usr/bin/osascript вы можете просто вернуть нужный текстовый вывод с помощью оператора return в конце вашего script.