我有一个在 TextMate 中构建的 Ruby 脚本,可以在TextMate中成功运行。我也可以直接从终端成功运行这个脚本。
该脚本中有这段代码:
# Get the XML file
puts 'Opening the file'
open("messages.xml", "r") do |f|
puts 'File is opened'
theXML = Hpricot::XML(f)
puts 'Trying to get the message_entity'
message_entity = GetMessage(theXML)
# Build the system command
puts 'Getting the author and the message'
theAuthor = message_entity.search(:author).text
theMessage = message_entity.search(:messagetext).text
# Get the correct image for this author
theAuthorImage = ''
case theAuthor
when 'James' : theAuthorImage = 'images/me32.png'
when 'Zuzu' : theAuthorImage = 'images/Zuzu32.png'
end
puts "/usr/local/bin/growlnotify '" + theAuthor + " says' -m '" + theMessage + "' -n 'Laurens Notes' --image '" + theAuthorImage + "'"
#system("/usr/local/bin/growlnotify '" + theAuthor + " says' -m '" + theMessage + "' -n 'Laurens Notes' --image '" + theAuthorImage + "'")
end
puts 'The End'
当脚本由GeekTool运行时,它永远不会过去puts 'File is opened'。它甚至没有击中puts 'The End'。它根本没有错误。
该脚本位于我 Mac 上文件夹下的一个文件夹下/System,但我已更改文件权限以允许“每个人”具有“读写”访问权限。
编辑
我刚刚将文件复制到我的用户主文件夹下的一个文件夹中,它在 GeekTool 中仍然存在问题,但在 TextMate 中或直接通过终端没有。
结束编辑
第二次编辑
我认为 GeekTool 可能存在文件路径问题。
例如,我将程序更改为现在直接从 Internet 读取 XML 文件,并且效果很好,但是程序使用了一些图像来显示growlnotify中的图标。通过 TextMate 运行时,这些图标显示完美。使用 GeekTool 运行时...不。根本没有自定义图标。
It's as if GeekTool just can't handle the file paths correctly.
When I do puts __FILE__.to_s it gives me the correct filepath to my .rb file though.
** end 2nd edit** What should I do?