Applescript Custom Folder View.

I've been fooling around for many hours and can't seem to wrap my head around the correct syntax of the AppleScript to do what I need it to.

Ideally I would like this to happen.

I select a number of folders in the finder. I would open each folder and set the following properties to it.

Tell application finder

bounds {0, 46, 2560, 1440}

icon size 36

toolbar view false

view to icon view

close the window

end tell

I was able to get parts of it to work but not as a whole and wasn't able to find the correct language to use on the icon size. Any help and or advice is appreciated.

iMac (27-inch, Late 2012), OS X Mountain Lion (10.8.4)

Posted on Jun 5, 2015 2:08 AM

Reply
6 replies

Jun 5, 2015 6:31 AM in response to desioner

Hello


You may try something like the script below. It is assumed that Finder is set to open folder in new window.



tell application "Finder" repeat with a in (get selection as alias list) if item a's class = folder then tell item a open tell its container window set toolbar visible to false set bounds to {0, 46, 2560, 1440} -- {l, t, r, b} set current view to icon view tell its icon view options set icon size to 36 end tell end tell close end tell end if end repeat end tell




Briefly tested under OS X 10.6.8.


Good luck,

H

Jun 5, 2015 9:15 PM in response to Hiroto

Great work there Hiroto!

That's exactly what I was thinking. I recall reading various places as I was trying to get this language that a folder with a .DS_Store file will not remember these changes. It's true that after running the script the changes do not stick. Perhaps I should delete the DS files first. Is it possible to add that into the script.

If folder contains .DS_Store then delete

if that were to happen then the settings I guess would then be saved to the newly created .DS_Store.

Unless that's not really the way DS files work.

In any case your help was appreciated and you figured out perfectly what i wanted.

Thank you very much,

D

Jun 5, 2015 10:50 PM in response to desioner

And technically this was just the first step of ultimately what I wanted to do. I was thinking to run a system event for keystrokes for these folders after the size & view options were set. However with the size and view options not actually sticking perhaps it best if I get the keystrokes before the window is closed.

The final product of the script it to automatically take a screen capture of a hundred folders and their contents.

So the key strokes I was thinking was to:

tell application "System Events"

if UI elements enabled then

tell process "Finder"

keystroke "v" using command, option, shift down -- Open Snapz

delay 1

keystroke return --select window

delay 1

keystroke return --snap window

delay 1

end tell

end if

end tell

So that each window would be opened, view options set. Snapz opens takes the snap and the window closes.

But I'm really not sure how to go about nesting these together.

If the folders would remember the view options I could, in a worst case scenario manually snap the folders.

Jun 6, 2015 3:39 PM in response to desioner

Hello


Sadly, Finder in recent OSes may not remember the last view options per folder. For me, Finder has been a junk of which flaws I'd not pursue too far...


I don't know Snapz but if you're just capturing Finder window image under OS X 10.8, you migth use screencapture(1) command which, if I'm not mistaken, has undocumented -l option to capture window of specified window id. (I cannot test it, for I use OS X 10.6.8 where screencapture(1) does not have -l option).



Something like the script below, which will save folder window image in _folder_preview.png in each folder.



tell application "Finder" repeat with a in (get selection as alias list) tell item a if its class = folder then open tell its container window set toolbar visible to false set bounds to {0, 46, 2560, 1440} -- {l, t, r, b} set current view to icon view tell its icon view options set icon size to 36 end tell my windowcapture(id, a's POSIX path & "_folder_preview.png") end tell close end if end tell end repeat end tell on windowcapture(wid, outfile) (* integer wid : window id string outfile : POSIX path of ouput file *) do shell script "screencapture -l " & wid & " " & outfile's quoted form end windowcapture




Hope this may help,

H

Jun 7, 2015 6:50 AM in response to desioner

You're quite welcome! Glad to be of help. 🙂



By the way, you can capture the window area only without window framing effect by using -o option of screencapture if you want to. For that, you may use the following windowcapture() handler.



on windowcapture(wid, outfile) (* integer wid : window id string outfile : POSIX path of output file *) do shell script "screencapture -o -l " & wid & " " & outfile's quoted form end windowcapture




Best wishes,

Hiroto

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript Custom Folder View.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.