Title: [ANN] New script, List script shortcuts
I've written a script that I have needed for myself for ages. I'll include it below for those who don't want to bother downloading, but I will post it to AppleScript central, and to my iDisk (see the URL in the sig below) for later access.
This script does a very useful thing for anyone using a lot of scripts: It generates a sorted list of all the keyboard shortcuts that you have assigned to scripts in your Entourage script menu (including subfolders to one level).
I have often had to search through my script menu trying to find out why the shortcut I just assigned does not work, because it has been duplicated on another script somewhere in the mess of scripts I have. Now, my script will generate a list, sorted by the primary key. That is, if you have Control-A and Control-B assigned as shortcuts, it will sort the "A" command before the "B" one, so you can easily detect duplications.
If you need a list sorted by the script/command name, you'll need to copy it to some other program to sort the list. (Maybe v2 of the script will allow choice of sort sequence, but that's a bit tricky.)
The list will look something like this:
A+Opt+Ctl--------1. Display In Box
B+Ctl+Cmd--------Open Unread Messages
B+Opt+Ctl--------2. Display Out Box
C+Opt+Cmd--------Copy Source to clipboard
Notice that if you are displaying in a proportional font the columns don’t line up; if you display with a monospace font (like Courier), they will.
Here is the script. Copy and paste into Script Editor, compile, and store it (using name of your choice, I call it "List Keyboard Shortcuts") into your Entourage Script Menu Items folder.
(* Comments for the comment block at the top:
List Keyboard Shortcuts - Allen Watson, October, 2001
Scans the current Entourage Script Menu Items folder, and all its subfolders, and builds a list of all scripts with Keyboard shortcuts defined (with a suffix beginning with backslash); decodes the shortcuts and builds a list of shortcut keys for the scripts. The list is placed into a new draft message window.
*)
property modKeys : {"c", "m", "o", "s"}
property modNames : {"Ctl", "Cmd", "Opt", "Shf"}
property offsetSentinal : ASCII character 1 -- speed up repeated calls
property mudF : ""
tell application "Microsoft Entourage"
-- Locate scripts folder
set v to version
if v begins with "10" then
set mudF to path to MUD
else
set mudF to choose folder with prompt "Please locate your Microsoft User Data folder"
end if
set scriptFolder to ("" & mudF & "Entourage Script Menu Items:")
end tell
--First build a list of all script file names
set scriptList to {} -- Start with empty list
tell application "Finder"
set scriptFolder to alias scriptFolder
set scriptList to name of (every file of scriptFolder whose name contains "\\")
set subFolders to every folder of scriptFolder
repeat with aFolder in subFolders
set aFolder to aFolder as alias
set tempList to {}
try
set tempList to name of (every file of aFolder whose name contains "\\")
set scriptList to scriptList & tempList
end try
end repeat
set shortcutTable to {}
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\\"
repeat with aScript in scriptList
set aScript to aScript as string
set aScript to text items of aScript
set scriptName to item 1 of aScript
set shortcut to item -1 of aScript
set achar to ""
set theKey to character -1 of shortcut -- The keyboard key
--Now decode the modifier keys
set modList to {}
repeat with i from 1 to (count shortcut)
set achar to character i of shortcut
set ptr to my offsetOf(modKeys, achar)
if ptr ? 0 then copy item ptr of modNames to end of modList
end repeat
set modList to my sortL(modList)
copy scriptName to beginning of modList
copy theKey to end of modList
copy modList to end of shortcutTable
end repeat
-- return shortcutTable
set AppleScript's text item delimiters to od
-- get shortcutTable
-- Now format the list into a tabular message
set theBody to ""
repeat with k in shortcutTable
set lim to (count k)
set sep to "+"
set str to item -1 of k -- Put the key first for sorting
repeat with i from lim - 1 to 1 by -1
if i = 1 then
--Pad with dashes to length of 17
repeat while (length of str < 17)
set str to str & "-"
end repeat
set str to str & item 1 of k
else
set str to str & sep & item i of k
end if
end repeat
set theBody to theBody & str & return
end repeat
--Sort the list by primary key
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set tempList to text items of theBody
set tempList to my sortL(tempList)
set theBody to tempList as text
set AppleScript's text item delimiters to od
--Finally, present the report in a new draft window in Entourage
set theDate to (current date) as string
tell application "Microsoft Entourage" to make new draft window with properties {subject:"Script Menu Keyboard Shortcuts as of " & theDate, content:theBody}
beep 3
end tell
on offsetOf(a, s) -- case-sensitive
set oldDelim to text item delimiters
set text item delimiters to offsetSentinal
set a to offsetSentinal & a & offsetSentinal
set x to offset of (offsetSentinal & s & offsetSentinal) in a
if (x is not 0) then
set x to count of text items in (a's text 1 thru x)
set x to x - 1
end if
set text item delimiters to oldDelim
return x
end offsetOf
on sortL(l)
if length of l ? 1 then return l
set x to item 1 of l
set ll to rest of l
set l1 to {}
set l2 to {}
repeat with i in ll
if x < i then
set l2 to l2 & i
else
set l1 to l1 & i
end if
end repeat
if length of l1 > 1 then set l1 to sortL(l1)
if length of l2 > 1 then set l2 to sortL(l2)
return l1 & x & l2
end sortL
- Re: [ANN] New script, List script shortcuts Allen Watson
- Re: [ANN] New script, List script shortcuts Allen Watson
- Re: [ANN] New script, List script shortcuts Paul Berkowitz
