从itunes读取歌词并制作文件
我从 http://www.dougscripts.com/itunes/ 得到提示来提出以下代码。但它还需要更多改进。
- 完成文件生成后出现错误 http://a.imageshack .us/img831/1610/screenshot20100804at113l.png,出了什么问题?
- 我不需要使用“TextEdit”来存储文件,是否有更好的方法将信息存储到文件中?
tell application "iTunes" if player state is playing then set sel to current track as list else if selection is not {} then set sel to selection end if set noSong to "" set summaryFile to ((path to desktop as Unicode text) & "songs2.txt") set ff to open for access file summaryFile with write permission repeat with this_track in sel set the_lyrics to this_track's lyrics set {art, nom} to {this_track's artist, this_track's name} if the_lyrics is not "" then tell application "TextEdit" activate set myVar to art & nom & the_lyrics write myVar to ff starting at eof end tell else beep end if end repeat end tell
I got hints from http://www.dougscripts.com/itunes/ to come up with the following code. But it needs much more improvements.
- I got error when I'm done with the file generation, http://a.imageshack.us/img831/1610/screenshot20100804at113l.png, what's wrong?
- I don't need to use "TextEdit" for storing a file, is there better way just store the info to the file?
tell application "iTunes" if player state is playing then set sel to current track as list else if selection is not {} then set sel to selection end if set noSong to "" set summaryFile to ((path to desktop as Unicode text) & "songs2.txt") set ff to open for access file summaryFile with write permission repeat with this_track in sel set the_lyrics to this_track's lyrics set {art, nom} to {this_track's artist, this_track's name} if the_lyrics is not "" then tell application "TextEdit" activate set myVar to art & nom & the_lyrics write myVar to ff starting at eof end tell else beep end if end repeat end tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我用来管理将数据写入文本文件的两个子例程:
请注意 write_to_file() 是 Apple 在 Essential Subroutines 中来自他们自己的旧 Applescript 站点的代码。 WriteToLog() 是我自己的子例程,它只使用一个参数(文本本身)与 write_to_file 进行交互。加盐调味。要重写脚本以适应上述子例程,我会这样做:
Here are two subroutines I use to manage writing data to a text file:
Please note write_to_file() is Apple's code from their own old Applescript site in Essential Subroutines. WriteToLog() is my own subroutine that wrote to interface with write_to_file with only one argument, the text itself. Add salt to taste. To rewrite the script accomodate the above subroutines, I would do it like this:
你只是有一些超出范围的事情,所有文本文件的打开、关闭和写入都必须在 itunes 之外完成,并且不需要 texedit
you just had some things out of scope all the opening closing and writing of the text file must be done outside of itunes and texedit is not needed