How am I doing? (Script requires 24U Appearance OSAX)
How am I doing? (Script requires 24U Appearance OSAX)
- Subject: How am I doing? (Script requires 24U Appearance OSAX)
- From: Mr Tea <email@hidden>
- Date: Tue, 24 Sep 2002 19:19:05 +0100
Hi, all.
I've knocked up a script to help manage some startup items that I don't wish
to include in the 'Login Items' list (they get opened/run by a startup
script that runs at login). My efforts are reproduced below. As usual, they
are based on the technique of throwing stuff into the script until something
works, and in the continued pursuit of my ambition to be the most competent
AppleScripter in Wales, I would welcome any feedback and suggestions for
streamlining the script.
I used the 24U Appearance OSAX 'display better dialog' command to make a
dialog with checkboxes & more than 3 buttons. It came generously bundled
with the freeware 'Trash It!' package, and I was so impressed that I stumped
up for the licenced version. Both the OSAX and Trash It! can be found at
http://www.versiontracker.com/macosx/
Here's the script. Longish, I'm afraid, so, many thanks to anyone who has
the patience to trawl through it.
(* ***
step 1 - write folder locations & contents to
variables for use later in script
*** *)
set startupItems to alias "Mezzanine!:Users:ndt:Startup Items:"
set disabledItems to alias "Mezzanine!:Users:ndt:Startup Items:Disabled:"
tell application "Finder"
set onList to (name of every file of startupItems)
set offList to (name of every file of disabledItems)
end tell
(* ***
step 2 - generate a list of names in the desired format
for displaying in my dialog - originally done with offsets,
but now rejigged to use TIDs on the advice of more
experienced scripters. All my startup items have a numerical
prefix added to their names (to govern launch order) -
this is stripped out for display purposes by the first part
of the repeat loop: messy name extensions are stripped out
in the second part
*** *)
set masterList to onList & offList
set newList to {}
repeat with theName in masterList
set AppleScript's text item delimiters to " "
set theInterimName to (text items 2 thru -1 of (theName as string))
set AppleScript's text item delimiters to "."
set theDisplayName to text item 1 of theInterimName
set AppleScript's text item delimiters to ""
set newList to newList & theDisplayName
end repeat
(* ***
step 3 - blag the ASCII sort routine from the guidebook modules
*** *)
set newList to ASCII_Sort(newList)
(* ***
step 4 - set default value of true/false variables
used to set 'selected' property of 24U check boxes...
I'm sure there must be a better way to do this
*** *)
set {checkOne, checkTwo, checkThree, checkFour, checkFive, checkSix,
checkSeven, checkEight, checkNine, checkTen} to {false, false, false, false,
false, false, false, false, false, false}
(* ***
step 5 - check each startup item to see if it's enabled
*** *)
if item 1 of newList is in (onList as string) then set checkOne to true
if item 2 of newList is in (onList as string) then set checkTwo to true
if item 3 of newList is in (onList as string) then set checkThree to true
if item 4 of newList is in (onList as string) then set checkFour to true
if item 5 of newList is in (onList as string) then set checkFive to true
if item 6 of newList is in (onList as string) then set checkSix to true
if item 7 of newList is in (onList as string) then set checkSeven to true
if item 8 of newList is in (onList as string) then set checkEight to true
(* ***
step 6 - set the properties/parameters for the
'display better dialog' command, and display the dialog
*** *)
set theDialog to "Startup Items Manager" & return
set fieldOne to {kind:check box, name:(item 1 of newList) as string,
selected:checkOne}
set fieldTwo to {kind:check box, name:(item 2 of newList) as string,
selected:checkTwo}
set fieldThree to {kind:check box, name:(item 3 of newList) as string,
selected:checkThree}
set fieldFour to {kind:check box, name:(item 4 of newList) as string,
selected:checkFour}
set fieldFive to {kind:check box, name:(item 5 of newList) as string,
selected:checkFive}
set fieldSix to {kind:check box, name:(item 6 of newList) as string,
selected:checkSix}
set fieldSeven to {kind:check box, name:(item 7 of newList) as string,
selected:checkSeven}
set fieldEight to {kind:check box, name:(item 8 of newList) as string,
selected:checkEight}
set theFields to {fieldOne, fieldTwo, fieldThree, fieldFour, fieldFive,
fieldSix, fieldSeven, fieldEight}
set theButtons to {"Done", "Restart", "Log Out", "Er..."}
onList as string
tell application "Finder"
activate
set StartupSelection to display better dialog theDialog fields theFields
buttons theButtons default button 1
end tell
(* ***
step 7 - respond to the results returned by
the dialog - I am fully expecting to be told that
using the routine 'if "string" is in "longer string"
then...' is hopelessly slow and inefficient
*** *)
set theFields to the fields returned of StartupSelection
if the button returned of StartupSelection is not "Er..." then
repeat with aField in theFields
if selected of aField is true and (((name of aField) as string) is
in (offList as string)) then
tell application "Finder"
move (every file of disabledItems whose name contains ((name
of aField) as string)) to startupItems
end tell
else if not selected of aField and (((name of aField) as string) is
in (onList as string)) then
tell application "Finder"
move (every file of startupItems whose name contains ((name
of aField) as string)) to disabledItems
end tell
end if
end repeat
if the button returned of StartupSelection is "Log Out" then
tell application "Logout Script" to activate
end if
if the button returned of StartupSelection is "Restart" then
tell application "Restart Script X" to activate
end if
end if
(* ***
finally, that off the peg handler - see step 3 above
*** *)
on ASCII_Sort(my_list)
set the index_list to {}
set the newList to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of newList to the low_item
set the end of the index_list to the low_item_index
end repeat
return the newList
end ASCII_Sort
Cordially
Mr Tea
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.