Folder Actions - The Jon Pugh Challenge
Folder Actions - The Jon Pugh Challenge
- Subject: Folder Actions - The Jon Pugh Challenge
- From: Mr Tea <email@hidden>
- Date: Thu, 16 Aug 2001 01:56:55 +0100
The story so far...
Akua Sweets 'reposition window' does not seem to offer a solution to Jon's
desire for an auto-resizing popup window. Sure enough, the bounds of the
popup window can be reset, but it's bad mojo because the window, still in
it's popup state, seems to lose it's connection with the bottom edge of the
screen and the Finder apparently becomes confused about the window's status.
And crucially, given Jon's stipulation that the tab should live in the
bottom right corner of his desktop, the position of the tab in relation to
the window cannot be scripted. (Correct me if I'm wrong.)
So, here's a script that does part of the job... but first, some notes.
This effort rejects any non-aliases dragged into it and resizes the window
based on the number of icons it contains, limiting it's maximum height to
half that of the desktop. The script does position the window at the bottom
right of the screen, but without OneClick (or similar), the window will
still need to be dragged back into a popup state.
The calculations used to resize the window are based on the amount of screen
space that each icon takes up (136, 17) when the views font is set to Geneva
9pt in the Apperance control panel, the view is set to small icon, and tight
spacing is selected in the Finder's preferences dialog. That's a lot of
conditions to be met, I know (all based on Jon's specs), so the script is
not very portable at present, and it may resize the window incorrectly if
any of the items in the folder has an excessively long name that displaces
an icon in the next column. (In the unlikely event that Jon has his Finder
prefs set to 'wide spacing', the figures above change to 182, 22)
The script is actually two folder actions, add and remove - that's a little
bonus feature for you, Jon, in anticipation of the possibility that you
might sometimes want to remove items from your pop-up alias folders. I
nearly lost my grip on reality finding a way to get the 'remove' folder
action to ignore non-aliases rejected by the 'add' folder action, but the
somewhat bug-eyed solution I came up with should work in all concievable
circumstances.
As always, I welcome any comments/howls of derision from the more
experienced scripters on this list. Using a handler is a bit of an adventure
for me, so the related syntax may not be optimal, but I have at least tried
follow the principles of Mr JollyRoger's anti-tell-block-abuse campaign.
Mind the line wraps...
~~~~~~~~~~~~~~~~~
on adding folder items to theFolder after receiving theItems
set rejectedItems to {}
repeat with i in theItems
if alias of (info for i) is false then set rejectedItems to
rejectedItems & i
end repeat
tell application "Finder" to move rejectedItems to desktop
if (count of rejectedItems) < (count of theItems) then my
resizeTheWindow(theFolder)
end adding folder items to
on removing folder items from theFolder after losing theItems
set standEasy to false
copy item 1 of theItems to theMarker
tell application "Finder"
if exists item theMarker of the desktop then
if kind of item theMarker of the desktop is not "alias" then set
standEasy to true
end if
end tell
if standEasy is false then my resizeTheWindow(theFolder)
end removing folder items from
on resizeTheWindow(theFolder)
tell application "Finder"
copy bounds of the desktop's window to theScreenSize
set theItemCount to (count of items of theFolder)
set theWindow to window of theFolder
end tell
copy {item 3 of theScreenSize, item 4 of theScreenSize} to {xPos, yPos}
set theMaxHeight to (yPos / 2) as integer
set theMaxColumnHeight to round ((theMaxHeight - 37) / 17)
set theRowWidth to 136
set theRowCount to 1
repeat
if (theItemCount / theRowCount) > theMaxColumnHeight then
set theRowCount to theRowCount + 1
else
set {theIdealHeight, theBestWidth} to {(round (theItemCount /
theRowCount) * 17) + 52, (theRowWidth * theRowCount) + 20}
if theIdealHeight < 144 then set theIdealHeight to 144
exit repeat
end if
end repeat
set theNewBounds to {xPos - theBestWidth, yPos - theIdealHeight, xPos,
yPos}
tell application "Finder"
set popup of theWindow to false
set the bounds of theWindow to theNewBounds
end tell
end resizeTheWindow
~~~~~~~~~~~~~~~~~
I'd be interested to hear if any other AS listers (the few still using
pre-0S X systems anyway) have tried using Akua Sweets 'reposition window' on
popups, and with what result.
Cheers
Mr Tea
--
Brew of the day: Ceylon
Visit the Tea Room at:
http://homepage.mac.com/mrtea/tearoom.html