Reputation: 43
I'm trying to get the bounds of my desktop window by using applescript with the following code:
tell application "Finder"
get bounds of window of desktop
end tell
I keep getting "execution error: Finder got an error: Can’t get bounds of window of desktop. (-1728)".
I'm running Lion. Any idea how I can get this to work?
Upvotes: 4
Views: 3337
Reputation: 5055
The Desktop and a window are two different things. The Desktop is actually a folder located at Macintosh HD:Users:yourusername:Desktop:
. If you mean that you want to get bounds of a window in the Finder, then you need to identify the window in question. Something like this will work...
tell application "Finder"
set windowCount to (count windows)
if windowCount > 0 then
set windowBounds to bounds of window 1 --> Note the '1'
return windowBounds
end if
end tell
Note the checking to see if any windows are actually open as Applescript will return an error if there are no windows open.
If you are looking to get the bounds of your screen, then all you need is the following...
tell application "Finder"
get bounds of window of desktop --> weird but that's Applescript for you
end tell
--> Result: {0, 0, 1440, 900}
If the ability to quit the Finder or make it disappear is enabled, then the above will not work.
Upvotes: 6