Ruby, Mac, Geektool question, file access rights?

后端 未结 3 829
日久生厌
日久生厌 2021-01-25 06:42

I have a Ruby script that I built in TextMate and can successfully run in TextMate. I can also successfully run this script straight from the terminal.

The script has th

相关标签:
3条回答
  • 2021-01-25 07:16

    Try wrapping it all in a block like below, which will log to /tmp/geektool.txt. Then you can see if there are any exceptions happening that you aren't aware of (like file permission).

    begin
      #file.open... etc
    rescue Exception => e
      file.open('/tmp/geektool.txt', 'w'){|f| f.puts "#{e}\n\n#{e.backtrace}"}
    end
    

    Also, don't forget there's the ruby-growl gem.

    0 讨论(0)
  • 2021-01-25 07:27

    Have you checked if GeekTool spews any output to console.log or system.log?

    Also, if it never gets past 'File is opened', it might be an issue with gems and requiring Hpricot?

    0 讨论(0)
  • 2021-01-25 07:28

    Geektool runs all the commands from / so relative path names will not work when trying to run growlnotify.

    puts Dir.pwd  #outputs "/"
    

    You will need to pass the absolute paths of the images to growlnotify.

    The current path can be retrieved with

    File.dirname(__FILE__)
    

    So you would use

    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
    
    0 讨论(0)
提交回复
热议问题