Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'a Ruby version that dynamically gets the list of Login Items to launch' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
a Ruby version that dynamically gets the list of Login Items to launch
Authored by: HotFusionMan on Oct 20, '10 09:34:49PM

I really wanted the script to automatically know what my Login Items are instead of manually making aliases in a folder for it. Based on this previous comment I was able to bang out a Ruby version (much quicker for me than modifying the AppleScript code). It retains the Growl setup but omits the capability of launching the Login Items in the background (so I could actually finish the script tonight rather than next week ;) ).

Save the following code to a file and chmod +x that file in Terminal.app (or whatever shell you prefer) so it can be executed. I haven't gone all the way through to testing making it the sole Login Item the way one would ultimately want to, but I did confirm it works with the stock /usr/bin/ruby without needing any 3rd-party libraries (at least on Snow Leopard, but I believe any version of Ruby >= 1.8 should also work, because that's when REXML was included into the Ruby standard library).

Caveat emptor.

#!/usr/bin/env ruby

require 'rexml/document'

def set_up_Growl
  if `ps -ax | grep GrowlHelperApp\.app | grep -v grep` == '' then
    system( 'open /Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app' )
  end
end

set_up_Growl

loginitems_plist_xml = `plutil -convert xml1 -o - -- ~/Library/Preferences/com.apple.loginitems.plist`

REXML::Document.new( loginitems_plist_xml ).each_element( '/plist/dict/dict/array/dict/dict/dict' ) { |login_item_dict|
  index_of_Path_key = i = 0 ; elements = []
  login_item_dict.each_element { |e|
    elements << e

    if e.text == 'Path' then
      index_of_Path_key = i
    end

    i += 1
  }

  login_item = elements[index_of_Path_key + 1].text
  system( "open '#{login_item}'" )
  sleep( 1 )
}
</pre>

     

[ Reply to This | # ]