我有一个用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可能在文件路径方面有问题。
例如,我将程序更改为直接从互联网读取XML文件,这样做很好,但是该程序正在为咆哮通知中的图标使用一些图像。在运行TextMate时,这些图标显示得非常完美。当使用GeekTool...nope运行时。根本没有自定义图标。
就好像GeekTool无法正确地处理文件路径。但是,当我执行puts __FILE__.to_s时,它会给我.rb文件正确的文件路径。
**结束第二版**我该怎么办?
发布于 2009-12-20 23:49:19
Geektool运行/所以当试图运行growlnotify时,相对路径名将无法运行所有命令。
puts Dir.pwd #outputs "/"您需要将图像的绝对路径传递给growlnotify。
当前路径可以使用
File.dirname(__FILE__)所以你会用
theAuthorImage = File.dirname(__FILE__)
case theAuthor
when 'James' : theAuthorImage += '/images/me32.png'
when 'Zuzu' : theAuthorImage += '/images/Zuzu32.png'
end
cmd = "/usr/local/bin/growlnotify '#{theAuthor} says' -m '#{theMessage}' -n 'Laurens Notes' --image '#{theAuthorImage}'"
puts cmd
system cmd发布于 2009-12-10 20:37:42
尝试将其包装在如下所示的块中,这将记录到/tmp/geektool.txt。然后,您可以看到是否存在任何您不知道的异常(比如文件权限)。
begin
#file.open... etc
rescue Exception => e
file.open('/tmp/geektool.txt', 'w'){|f| f.puts "#{e}\n\n#{e.backtrace}"}
end还有,别忘了那是红宝石。
发布于 2009-12-12 10:14:22
您是否检查过GeekTool是否向console.log或system.log输出了任何输出?
此外,如果它从来没有通过‘文件是打开’,这可能是一个问题的宝石和需要杏树?
https://stackoverflow.com/questions/1883664
复制相似问题