Ruby, Mac, Geektool question, file access rights?

后端 未结 3 828
日久生厌
日久生厌 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: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
    

提交回复
热议问题