Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

open finder window on a specified place on the screen

Hello,

In trying to somehow replicate the drop stack in PathFinder (www.cocoatech.com), I use a very simple script that I save as app bundle and place on the finder toolbar. The script is

do shell script "open /Users/myusername/temp"

I know this is not quite Applescript, but it works 🙂.

I have two questions to improve my little script

1) Is there a way to force the new finder window to open on a specified place on screen (ideally to the side of and flushed against the window from which it was called)

2) If I close the "temp" window without toolbar and sidebar (click on the oval top-right button), it will come that way when called again. However, I may forget sometimes to close temp that way. Is there a way to force a finder window to be opened without toolbar and sidebar?

Any help will be appreciated.

Thanks,

MarceloC

MacBook Pro, Mac OS X (10.5.1)

Posted on Dec 11, 2007 2:44 PM

Reply
Question marked as Best reply

Posted on Dec 11, 2007 5:55 PM

Hi MarceloC

something along the lines of below seems like a start


tell application "Finder"
activate
set _Window to 1
make new Finder window
set bounds of (Finder window _Window) to {100, 100, 500, 500}
set current view of (Finder window _Window) to list view
set toolbar visible of (Finder window _Window) to false
set the sidebar width of the (Finder window _Window) to 0
end tell


Budgie
10 replies
Question marked as Best reply

Dec 11, 2007 5:55 PM in response to MarceloC

Hi MarceloC

something along the lines of below seems like a start


tell application "Finder"
activate
set _Window to 1
make new Finder window
set bounds of (Finder window _Window) to {100, 100, 500, 500}
set current view of (Finder window _Window) to list view
set toolbar visible of (Finder window _Window) to false
set the sidebar width of the (Finder window _Window) to 0
end tell


Budgie

Dec 11, 2007 11:31 PM in response to Budgie

Thank you!

I put my "do shell script..." bit instead of your "make new Finder window", and it works like a charm! If I could make it flush to the calling window, I'd be an even happier camper, but this works very nicely indeed.

Just a question. In "set _Window to 1", the "1" represents the latest opened window? How would you represent the window that was active before creating the new one? WIth a "2"?

If I know this, I guess there should be a way to ask Finder for the geometry of that window. If I know that, I should be all set with your script as starting point!

Thanks budgie, you always solve my questions in no time 🙂

MarceloC

Dec 12, 2007 2:17 AM in response to MarceloC

I think I answered my own question, thanks to an older post by Camelot on another topic. I use the following script

tell application "Finder"
set {l, t, r, b} to bounds of (Finder window 1)
do shell script "open /Users/myusername/temp"
set bounds of (Finder window 1) to {l - 305, t, l - 5, t + 300}
set current view of (Finder window 1) to icon view
set toolbar visible of (Finder window 1) to false
set the sidebar width of the (Finder window 1) to 0
set statusbar visible of (Finder window 1) to false
end tell

This works like a charm! Now my appetite is whetted, so I want an even more refined script 🙂. I tried to set the path bar to invisible (which I have visible by default), but failed. I tried with "set pathbar visible...", but that did not work. Maybe the Path Bar is a global property for all finder windows and cannot be set individually?

Also, expressions of the form

set the iconsize of (Finder window 1) to X (or with textsize or gridsize)

are accepted and compiled by Script editor. However, all my attempts at puting a value for X led to an error at execution time. Is this the correct way to do this? What is the format to do it?

I guess an even more encompassing question is where does one find this kind of info (as in being able to know everything I can set for a window with applescript...)


Thanks again. This is a great support list!

MarceloC

Dec 12, 2007 2:34 AM in response to MarceloC

Try working with the this line:
set bounds of (Finder window _Window) to {100, 100, 500, 500} but consider that the window coordinates are (X1,Y1,X2,Y2). If you specify X1 = Y1 = 0, the window will be in the upper left corner of the screen. If you make Y1 about 45, it should be just below the screen menu bar.

The window width will be X2 - X1, its height Y2 - Y1. To get it flush with another window, you can do this either by playing with X2, or (if you know the X1 of the other window), calculating X2. Or you could set the overall width you want with X2 - X1 and then change the coordinates of the other window so that its X1 = X2 of the window you've opened. (Clear?!)

Window 1, 2, etc. indicates screen hierarchy -- Window 1 being frontmost of the Finder windows in this case.

To find the coordinates of the "other" window, make that window frontmost by clicking on it and then enter (and run) this single line in a separate script editor window:
bounds of window 1 of application "Finder"

Dec 12, 2007 5:26 AM in response to osimp

Thanks osimp,

I guess (as you can see from my previous message) I was thinking along the lines of your message as you were writing it 🙂

I kept working, and what I have now is

tell application "Finder"
set {l, t, r, b} to bounds of (Finder window 1)
tell application "Finder" to open "path:to:temp"
tell (Finder window 1)
set bounds to {l - 305, t, l - 5, t + 300}
set current view to icon view
set toolbar visible to false
set sidebar width to 0
set statusbar visible to false
end tell
tell icon view options of (Finder window 1)
set the icon size to 30
set the text size to 10
end tell
end tell

WHich works perfectly. The only minor annoyance now is that this script opens the new window in whatever place it was closed last time, and then moves it to the place specified for this run. I know I am being persnickety here, but I want to change it to open exactly on the right place the first time.

Can anyone tell me why the following does not work?

tell application "Finder" to open "path:to:temp" with properties {bounds:{l - 305, t, l - 5, t + 300}}

It compiles and open the window, but it ignores the "bounds"

Thanks again,

Marcelo

Dec 12, 2007 8:35 AM in response to MarceloC

Hello Marcelo,

You have good questing mind. I like it. ; )

As for 'open X with properties {...}' not working, it is simply because such syntax is not defined in the application's AppleScript dictionary. You can look into Finder's AppleScript dictionary for what you can use.
Having that said, what you're trying to do might be done by 'make new X at Y with properies {...}' statement, that most application supports.

I'd try something like this:
(Please copy code from this web page, not from subscribed email text)

--SCRIPT (Not tested)
set fp to (path to home folder from user domain as Unicode text) & "temp:" -- path to target folder
tell application "Finder"
set {l, t, r, b} to bounds of Finder window 1
set props to ¬
{target:item fp} & ¬
{bounds:{l - 305, t, l - 5, t + 300}} & ¬
{current view:icon view} & ¬
{toolbar visible:false} & ¬
{sidebar width:0} & ¬
{statusbar visible:false}
make new Finder window at front with properties props
tell icon view options of Finder window 1
set icon size to 30
set text size to 10
end tell
end tell
--END OF SCRIPT



Good luck,
H

Dec 12, 2007 10:37 AM in response to Hiroto

Dear Hiroto,

Thank you so very much for your help. Your suggestion works flawlessly, except for one thing. Your script does what is supposed to do, but opens the new window in the root folder, rather than the intended one.

This is strange, since the Event Log shows what I think are the right elements:

make new Finder window at beginning with properties {target:folder "temp" of folder "marcelo" of folder "Users" of startup disk, bounds:{732, 551, 1032, 851}, current view:icon view, toolbar visible:false, sidebar width:0, statusbar visible:false}
Finder window id 1105

Everything else in props works great. Moreover, this works fine:

tell application "Finder" to open fp with properties props

so we see again that fp has the right path.

If it is of any relevance, I am using Leopard (10.5.1), although I have not heard of anything radical changing in Applescript.

I'll keep trying. I want to get this done 🙂

MarceloC

Dec 13, 2007 8:54 AM in response to MarceloC

Hello Marcelo,

Hmm.
You mean the script is opening Finder window for startup disk or for your home directory? If so, I'd think it's due to bug or flaw in Finder's scripting. The event log only tells us that such event is sent to Finder and alas, there's no guarantee the event is to be processed as intended by Finder!
My last attempt would be to use {target:fp as alias} or {target:(POSIX path of fp) as POSIX file} instead of {target:item fp} in the previous post. It MIGHT work, though there's little hope.

--SCRIPT
set fp to (path to home folder from user domain as Unicode text) & "temp:" -- path to target folder
tell application "Finder"
set {l, t, r, b} to bounds of Finder window 1
set props to ¬
{target:fp as alias} & ¬
{bounds:{l - 305, t, l - 5, t + 300}} & ¬
{current view:icon view} & ¬
{toolbar visible:false} & ¬
{sidebar width:0} & ¬
{statusbar visible:false}
make new Finder window at front with properties props
tell icon view options of Finder window 1
set icon size to 30
set text size to 10
end tell
end tell
--END OF SCRIPT

I cannot test this by myself, for I don't use OSX. Sorry for that.
Good luck,
Hiroto

Dec 13, 2007 1:40 PM in response to Hiroto

Dear Hiroto,

No, neither of them worked. The finder opens in the start up disk (which I called root). I think you may be right that this is a bug in Finder scripting. I'll try to find a computer with Tiger to test, and if it works there, I'll report the bug.

Thanks again for all your help. In the end, I got almost the exact script I was hoping for 🙂

MarceloC

open finder window on a specified place on the screen

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