我正在尝试从终端运行AppleScript脚本,但我无法通过调用来打印任何内容
osascript myFile.scpt "/path/to/a/file"
Run Code Online (Sandbox Code Playgroud)
我尝试着:
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
Run Code Online (Sandbox Code Playgroud)
制表符分隔文件的格式如下:
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
Run Code Online (Sandbox Code Playgroud)
标签在这方面并没有真正表现出来:(
Rap*_*ert 16
运行AppleScript时#!/usr/bin/osascript,只需在脚本末尾返回所需的文本输出和return语句即可.
它不是很清楚你如何试图在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
Run Code Online (Sandbox Code Playgroud)
更新 2,回应评论.
如果我有一个制表符分隔文本文件,其内容为:
track Skin Deep Beady Belle Closer
Run Code Online (Sandbox Code Playgroud)
标签设置如下:track*TAB Skin Deep 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
Run Code Online (Sandbox Code Playgroud)
在终端运行:
/usr/bin/osascript ~/Documents/testOsa2.scpt ~/Documents/testTab.txt
Run Code Online (Sandbox Code Playgroud)
我回来了: 宋:皮肤深 - Beady Belle - 更接近
小智 5
根据第一个答案弄清楚了这一点:
copy "Hello World!" to stdout
Run Code Online (Sandbox Code Playgroud)