我正在尝试从终端运行AppleScript脚本,但我无法通过调用
来打印任何内容 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'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)
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
标签在这方面并没有真正表现出来:(
答案 0 :(得分:14)
使用#!/usr/bin/osascript
运行AppleScript时,您只需返回所需的文本输出,并在脚本末尾添加return语句。
答案 1 :(得分:7)
目前还不是很清楚如何在Termanil中运行它。 但我假设你已经用#!/ usr / bin / osascript保存了一个applescript文本文件, chmod'ed该文件能够执行它。
然后在终端中调用该文件。只需使用文件的路径。
更新:使用echo
#!/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 皮肤深层 TAB Beady Belle 的 TAB 强> *更紧密
脚本文件为:
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
在终端运行中:
/usr/bin/osascript ~/Documents/testOsa2.scpt ~/Documents/testTab.txt
我回来了: 歌曲:皮肤深层 - Beady Belle - 更接近
答案 2 :(得分:1)
根据第一个答案找出答案:
copy "Hello World!" to stdout