Sorry, I’m sure this has been asked, but I NEVER seem to be able find what I want when I do searches.
Want to get a selected file’s parent folder
tell application "System Events"
set theItemsFolder to container of selection
end tell
Then add it to the sidebar.
I’ve got UI code that will add the selected file to the sidebar
tell application "System Events"
launch
keystroke "t" using command down
end tell
but that won’t work in this case. I guess I need Finder code for “add to sidebar.”
Or…?
Model: Powerbook G4 1Ghz
AppleScript: 2.0
Browser: Firefox 1.5.0.2
Operating System: Mac OS X (10.4)
Containers belong to the Finder, I think, so:
tell application "Finder" to set theItemsFolder to container of (selection as alias) as alias
However, the only setting I can find for a Finder Window sidebar is to adjust its width.
Try something like this:
tell application "Finder"
activate
reveal (container of first item of (get selection))
end tell
tell application "System Events"
launch
keystroke "t" using command down
end tell
tell application "Finder" to close front Finder window
IT worked, sort of
I was finding it inconsistently adding the selected file itself, instead of its parent folder, to the sidebar.
Figuring it was just a weakness of the UI approach, I just added a
delay 2
and so far, so good!
Thanks cats