Ruby, Mac, GeekTool 질문, 파일 액세스 권한?
-
19-09-2019 - |
문제
제가 내 만든 루비 스크립트가 있습니다 텍스트 메이트 텍스트 메이트에서 성공적으로 실행할 수 있습니다. 또한이 스크립트를 터미널에서 바로 실행할 수도 있습니다.
스크립트에는이 코드 덩어리가 있습니다.
# 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'
. 전혀 오류가 없습니다.
스크립트는 아래의 폴더 아래에 있습니다 /System
Mac의 폴더이지만 "Everyone"가 "읽기 및 쓰기"액세스를 허용하도록 파일 권한을 변경했습니다.편집하다방금 파일을 사용자 홈 폴더 바로 아래의 폴더에 복사했지만 여전히 GeekTool에는 문제가 있지만 TextMate 또는 Terminal을 통해 직선에는 없습니다.
최종 편집
2 차 편집
GeekTool은 파일로가는 경로에 문제가있을 수 있다고 생각합니다.
예를 들어, 현재 인터넷에서 XML 파일을 바로 읽도록 프로그램을 변경했는데 그럴만 한 것이 좋습니다. 그러나 프로그램이 아이콘에 사용하는 이미지가 있습니다. Growlnotify. TextMate를 통해 실행되면이 아이콘이 완벽하게 표시됩니다. GeekTool을 사용하여 실행할 때 ... 사용자 정의 아이콘이 전혀 없습니다.
마치 GeekTool이 파일 경로를 올바르게 처리 할 수없는 것처럼 보입니다. 내가 할 때 puts __FILE__.to_s
그래도 .rb 파일에 올바른 FilePath를 제공합니다.
** 종료 2nd Edit ** 어떻게해야합니까?
해결책
GeekTool은 모든 명령을 실행합니다.
puts Dir.pwd #outputs "/"
으르렁 거리는 이미지의 절대 경로를 전달해야합니다.
현재 경로를 검색 할 수 있습니다
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
다른 팁
아래와 같은 블록으로 모든 것을 래핑하면 /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
또한 Ruby-Growl 보석이 있다는 것을 잊지 마십시오.
GeekTool이 Console.log 또는 System.log에 대한 출력을 뿌렸는지 확인 했습니까?
또한 '파일이 열린'과거를 절대로받지 못하면 보석과 HPRICOT가 필요한 문제 일 수 있습니까?