Hello,
I’ve just wrote my first script, so please forgive me if my question is to naif…
I would like to build a script to set all the folder’s windows within a disk to align at the top left of my screen when I open one of them. I’ve reached this point:
tell application "Finder"
activate
set my_list to every folder of the entire contents of disk "Backup"
open my_list
set every window to icon
set zoomed full size of every container window to true
clean up every container window by name
set size of every container window to {437, 200}
clean up every container window by name
set zoomed full size of every container window to true
set zoomed of every container window to true
close every window
end tell
The problem is this: when I put in the disk a folder with the views set to “list” the script hangs and display this message: “Window must be open in icon or small icon view to use this command”.
It seems the “set every window to icon” command does not help…
Can anyone please help?
Thank you.
João.
: Hello,
: I’ve just wrote my first script, so please forgive me if
: my question is to naif…
: I would like to build a script to set all the folder’s
: windows within a disk to align at the top left of my
: screen when I open one of them. I’ve reached this
: point: tell application “Finder”
: activate
: set my_list to every folder of the entire contents of
: disk “Backup”
: open my_list
: set every window to icon
: set zoomed full size of every container window to true
: clean up every container window by name
: set size of every container window to {437, 200}
: clean up every container window by name
: set zoomed full size of every container window to true
: set zoomed of every container window to true
: close every window end tell
: The problem is this: when I put in the disk a folder with
: the views set to “list” the script hangs and
: display this message: “Window must be open in
: icon or small icon view to use this command”.
: It seems the “set every window to icon” command
: does not help…
That’s not bad for a first script!
Unfortunately, the Finder’s ‘entire contents of’ operator has a bug and is unreliable. One way round this is to use a recursive handler (one that calls itself) to deal with the windows of all the folders and subfolders. You can avoid the error message you’re getting simply by not trying to clean up windows that are in list view.
The script below does everthing you want (I think). It’s a bit advanced, but I hope it helps. It doesn’t change list-view windows to icon view, as presumably the list view is what is wanted.
tell application "Finder"
activate
open disk "Backup"
-- Set window origin to {11,47}, size to {437,200}
set the bounds of the front window to {11, 47, 448, 247}
close window 1 -- Do the same for the windows of every folder and subfolder
my setWindows(disk "Backup")
end tell
on setWindows(theContainer)
tell application "Finder"
set theFolders to every folder of theContainer
if the result is not {} then
open theFolders
-- 'whose popup is false' in case there are popup windows on the desktop
set the bounds of every window whose popup is false to {11, 47, 448, 247}
clean up (every window whose popup is false and ¬
view is in {small, icon, small button, large button}) by name
close every window
repeat with thisFolder in theFolders
my setWindows(thisFolder)
end repeat
end if
end tell
end setWindows
NG
: tell application “Finder” activate open disk
: “Backup” – Set window origin to {11,47},
: size to {437,200} set the bounds of the front window
: to {11, 47, 448, 247} close window 1 – Do the same
: for the windows of every folder and subfolder my
: setWindows(disk “Backup”) end tell
: on setWindows(theContainer) tell application
: “Finder” set theFolders to every folder of
: theContainer if the result is not {} then open
: theFolders – ‘whose popup is false’ in case there are
: popup windows on the desktop set the bounds of every
: window whose popup is false to {11, 47, 448, 247}
: clean up (every window whose popup is false and ¬ view
: is in {small, icon, small button, large button}) by
: name close every window repeat with thisFolder in
: theFolders my setWindows(thisFolder) end repeat end if
: end tell end setWindows
OK, that’s my last contribution to this site until the script formatting’s sorted out.
NG
: okay… those numbers 1 and 2 should be 0 (small icons)
: and 1 (large icons). sigh sorry for the error.
“set view of every container window to 1”
Thank you very much for your answer. You are absolutely right; this line solved my problem 
Thanks!!! :-))))
: OK, that’s my last contribution to this site until the
: script formatting’s sorted out.
: NG
Nigel,
Thank you so much for your answer. I will try your script right now. I couldn’t format it before, since I’m new to AppleScript and your script is very complex (at least to me…).
Thank you again.
João.
"OK, that’s my last contribution to this site until the script formatting’s sorted out. "
I have had success with checking the “If you want your formatting” option checkbox prior to posting the message. Has it not worked for you?
“set every window to icon”
I didn’t try your full script, but I belive this should be
set view of every window to 1 – large icons set view of every window to 2 – small icons
and might be
set view of every container window to 1
grh
okay… those numbers 1 and 2 should be 0 (small icons) and 1 (large icons). sigh sorry for the error.
: Hello, I’ve tried the script too and it worked, but
: what I need is a little bit different, and can’t get
: it solved, maybe you can help me out. I want to
: set the view of every folder of a disk (and all
: subfolders) to list by name, but when I insert it in
: the script it doesn’t work. I think it only works in
: the frontmost window. Can you help me out?
: Thanks, Mars
Hi, Mars.
I assume you want every window to be ‘viewed as list’, arranged by name.
I get the same problem as you here. The cure seems to be to use an integervalue for the required view rather than the named value. Thus, instead of
:set the view of every container window whose popup is false to name…
you use
:set the view of every container window whose popup is false to 2
For your purposes, the script might look something like this
:----
set viewPref to 2 -- list view, sorted by name
tell application "Finder"
activate
open disk "My Disk
" -- Set the root window of the disk to the required view
set the view of the front container window to viewPref
close the front window
-- Do the same for the windows of every folder and subfolder
my setWindows(disk "My Disk", viewPref)
end tell
on setWindows(theContainer, viewPref)
tell application "Finder"
set theFolders to every folder of theContainer
if the result is not {} then
open theFolders
-- Use 'whose popup is false' in case there are popup windows on the desktop
set the view of every container window whose popup is false to viewPref
close every window
repeat with thisFolder in theFolders
my setWindows(thisFolder, viewPref)
end repeat
end if
end tell
end setWindows
----The possible view settings appear to be represented by the following integer values
0: small (ie. small icon)
1: icon
2: name
3: modification date
4: size
5: kind
6: comment
7: label
8: version
9: creation date
15: large button
16: small button
NG
Hello,
I’ve tried the script too and it worked, but what I need is a little bit different, and can’t get it solved, maybe you can help me out.I want to set the view of every folder of a disk (and all subfolders) to list by name, but when I insert it in the script it doesn’t work. I think it only works in the frontmost window. Can you help me out?
Thanks, Mars
: That’s not bad for a first script!
: Unfortunately, the Finder’s ‘entire contents of’ operator
: has a bug and is unreliable. One way round this is to
: use a recursive handler (one that calls itself) to
: deal with the windows of all the folders and
: subfolders. You can avoid the error message you’re
: getting simply by not trying to clean up windows that
: are in list view.
: The script below does everthing you want (I think). It’s
: a bit advanced, but I hope it helps. It doesn’t change
: list-view windows to icon view, as presumably the list
: view is what is wanted.
: tell application “Finder” activate open disk
: “Backup” – Set window origin to {11,47},
: size to {437,200} set the bounds of the front window
: to {11, 47, 448, 247} close window 1 – Do the same
: for the windows of every folder and subfolder my
: setWindows(disk “Backup”) end tell
: on setWindows(theContainer) tell application
: “Finder” set theFolders to every folder of
: theContainer if the result is not {} then open
: theFolders – ‘whose popup is false’ in case there are
: popup windows on the desktop set the bounds of every
: window whose popup is false to {11, 47, 448, 247}
: clean up (every window whose popup is false and ¬ view
: is in {small, icon, small button, large button}) by
: name close every window repeat with thisFolder in
: theFolders my setWindows(thisFolder) end repeat end if
: end tell end setWindows
: NG