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


Click here to return to the 'Adding and removing individual login items from Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Adding and removing individual login items from Terminal
Authored by: llee on Dec 27, '11 10:14:57AM

Here's an AppleScript to deal with login items already in the list.

--Run the script

--Select one or more login items from the list and click OK.

--Choose whether to reveal the login item in the Finder or to remove it from the current login items.

--See if it works for you! (Tip: try revealing 'em first and if you don't really want 'em removed after you test removing, just open login items in the Accounts (or Users and Groups) System prefpane and drag 'em back in there!)


tell application "System Events"

activate

set loginItems to name of every login item

choose from list loginItems with multiple selections allowed

end tell

set theResult to result

if theResult is false then

tell me to quit

else

activate

if (count of items of theResult) is not 0 then

if (count of items of theResult) is 1 then

display dialog "What do you want to do with" & space & every item of theResult & "?" buttons {"Cancel", "Reveal it", "Remove it"}

else

display dialog "What do you want to do with the selected login items?" buttons {"Cancel", "Reveal them", "Remove them"}

end if

if button returned of result contains "Remove" then

repeat with i in theResult

tell application "System Events"

delete (every login item whose name is (i as text))

end tell

end repeat

else if button returned of result contains "Reveal" then

repeat with i in theResult

set target_string to (do shell script "defaults read loginwindow | grep Path | grep" & space & (quoted form of i))

set this_offset to offset of "\"" in target_string

set x to text (this_offset + 1) thru -3 of target_string

tell application "Finder" to set home_path to (POSIX path of (path to "cusr"))

set actual_item to replace_chars(x, "~/", home_path)

set g to POSIX file actual_item

tell application "Finder"

activate

reveal g

end tell

end repeat

end if

end if

end if


on replace_chars(this_text, bahad, goohood)

set AppleScript's text item delimiters to the bahad

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the goohood as string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

return this_text

end replace_chars



[ Reply to This | # ]