Here is an example of a more fleshed out example...
Apple Mail
Within Mail I have 6 Mailbox folders within the Message Viewer window.
Here is what it looks like with the Inbox folder selected. The top of the palette matches the top of the selection, and the left of the palette is just beyond the longest name of the Mailboxes, i.e. Flagged. If the frame of the window changes, i.e., resizes or is moved on the screen, the macro is triggered and recalculates to position the palette in the same relative position with the folder icon. Each time the macro is triggered it first makes sure that the Mailbox area is showing in the Mail Message Viewer window, and sets the width of that area to 300 pixels in order to fit the current menu width without covering up the count of unread emails.
The palette is formatted to more closely resemble a context or drop-down menu. Only showing the text...
... and another example with the Junk folder selected.
Keyboard Maestro
Six separate palettes with each palette having a single macro that calculates and sets the location of the palette within the Mail Message Viewer window.
I set each palette to a different color just to illustrate that the palettes are changing as the different Mailbox folders are selected.
Here is an example of the setup for the Mail - Inbox macro group.
Within each group there is one macro, titled 99) to send it to the bottom of the palette with no label. The macro contains the AppleScript code to dynamically place the pallet with it's top matching the top of the selection banner of the appropriate Mailbox folder icon. The pallet will also be placed a distance to the right of the folder icon to allow the label to be seen. That distance is currently set to 80 pixels, enough to clear the longest folder name, i.e., Flagged.
AppleScript Macro for each Mail Macro Group
This is an example of the Applescript macro coming from the Mail - Inbox Macro group:
This Applescript macro is calling a Script Library which is located in the following location:
~/Library/Script Libraries/SetupMailPalettes.scpt
NOTE: You may have to create that location if it doesn't exist.
and it's contents are....
SetUpMailPalettes.scpt
on run
set folderName to "Inbox"
my doSetupOfMailboxFolder(folderName)
end run
on doSetupOfMailboxFolder(folderName)
set mailboxesAreaWidth to 300
set palettePositionAdjustment to 80
my setMailBoxesAreaWidth(mailboxesAreaWidth)
set {windowPosition, globalJunkFolderIconPosition, relativeJunkFolderIconPosition} to my determineMailFolderIconLocation(folderName)
set palettePosition to {(item 1 of globalJunkFolderIconPosition) + palettePositionAdjustment, item 2 of globalJunkFolderIconPosition}
my setPalettePosition("Mail - " & folderName, palettePosition)
end doSetupOfMailboxFolder
on setMailBoxesAreaWidth(mailboxesAreaWidth)
tell application "System Events"
tell process "Mail"
-- Make sure Mailbox List is showing
set showHideMailboxList to name of menu item 18 of menu 1 of menu bar item 5 of menu bar 1
if showHideMailboxList contains "Show" then
click menu item 18 of menu 1 of menu bar item 5 of menu bar 1
end if
-- Make sure Mailbox List area is wide enough to hold the palette without covering message count
if value of splitter 1 of splitter group 1 of window 1 is less than mailboxesAreaWidth then
set value of splitter 1 of splitter group 1 of window 1 to mailboxesAreaWidth
end if
end tell
end tell
end setMailBoxesAreaWidth
on determineMailFolderIconLocation(folderName)
tell application "System Events"
tell process "Mail"
tell window 1 to set windowPosition to position
set junkFolderRow to rows of outline 1 of scroll area 1 of splitter group 1 of window 1 whose (value of static text 1 of UI element 1 = folderName)
set globalJunkFolderIconPosition to position of image 1 of UI element 1 of first item of junkFolderRow
set relativeJunkFolderIconPosition to {(item 1 of globalJunkFolderIconPosition) - (item 1 of windowPosition), (item 2 of globalJunkFolderIconPosition) - (item 2 of windowPosition)}
return {windowPosition, globalJunkFolderIconPosition, relativeJunkFolderIconPosition}
end tell
end tell
end determineMailFolderIconLocation
on setPalettePosition(paletteName, newPalettePosition)
tell application "System Events"
tell process "Keyboard Maestro Engine"
set position of window paletteName to newPalettePosition
end tell
end tell
end setPalettePosition