gpt4 book ai didi

applescript - 使用applescript打印到Stdout

转载 作者:行者123 更新时间:2023-12-03 12:21:35 43 4
gpt4 key购买 nike

我正在尝试从终端运行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

选项卡的显示效果不是很好:(

最佳答案

还不清楚您如何尝试在Terminal中运行它。
但我假设您已经使用#!/usr/bin/osascript shebang保存了applescript文本文件,并且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

选项卡设置如下:
Track **** 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'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

我回来了:
*Song: Skin Deep - Beady Belle - Closer*

关于applescript - 使用applescript打印到Stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15605288/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com