Print to Stdout with applescript

Its is not very clear HOW you are trying to run it in Terminal. But I will assume you have saved a applescript text file with the #!/usr/bin/osascript shebang, and chmod'ed the file to be able to execute it.

Then called the file in Terminal, by just using the path to the file.

#!/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

Update 2, in response to comments.

If I have a tab delimited text file with the content as:

track   Skin Deep   Beady Belle Closer

The tabs are set like : track****TAB****Skin Deep****TAB****Beady Belle****TAB****Closer

And the script file as:

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's 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

Then in Terminal run:

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

I get back:

*Song: Skin Deep - Beady Belle - Closer*

Figured out this based on the first answer:

copy "Hello World!" to stdout

When running the AppleScript with #!/usr/bin/osascript, you can just return your desired text output with a return statement at the end of your script.

Tags:

Applescript