Set position of window?

Hi. Programming veteran, Applescript noobie here,

I’m making a script to automatically keep my windows arranged the way I like them.

I have one to marshal everything out of the reserved place on the left of the screen:


tell application "System Events"
    repeat with theApp in application processes
        if the name of theApp is not "Adium" and name of theApp is not "DashboardClient" and name of theApp is not "Finder" then
            repeat with theWin in windows of theApp
                set the position of theWin to {358, 22}
            end repeat
        end if
    end repeat
end tell

This script works just fine.

Now, I want to make one specifically for Adium, to autosize the chat window accourding to the contact list height, move the file transfers box and log viewer, if they’re open.

I begin…


tell application "Adium"
    
    repeat with theWin in windows
        set a to the name of theWin
        
        if a is "Contacts" then
            set cWin to the number of theWin
            set the position of theWin to {45, 22}
        else if a is "Log Viewer" then
            set lWin to the number of theWin
        else if a is "File Transfers" then
            set tWin to the number of theWin
        else if a is "" then
            set iWin to the number of theWin
        else
            set chWin to the number of theWin
        end if
    end repeat
    
    set position of window cWin to {45, 22}
end tell

Both calls to “set position of window”… fail here, no matter what I do, with error:

"Adium got an error: Can't make position of item 3 of every window into type reference."

However I write it, no matter what I do, I can’t treat theWin the same way I treat it in the first script… what am I missing? The event viewer seems to look exactly like the output of the first script, too… so it’s not like the window properties aren’t there…

– Dexter

(Also, any other syntax tips are appreciated)

Model: Macbook Pro
AppleScript: 1.10.7
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3
Operating System: Mac OS X (10.4)

Are you sure Adium (I don’t have it) is scriptable - look for its dictionary in your script editor - if it doesn’t have one, it’s not scriptable.

I can set the position of any window, reglardless of its scriptability in the first script. I can set the position of the Adium windows from the frist script. I avoid it explicitly though. I intend to add an event to adium for when people log in/out to autosize all the windows, and I don’t want to reposition the remainder of the windows at that time, just the Adium ones.

If I can’t ‘tell “Adium”’, how do I target a specific application and get the context of the first script? I know I can set window positions with the first script, but I don’t want to iterate through all my applications when I know the name of the one I want to get the windows of.

Why aren’t you doing this?


tell application "System Events"
	tell application process "Adium"
	
		--your script
	
	end tell
end tell

I have scripts that resize windows of unscriptable applications using System Events, but I don’t have Adium, and I haven’t tried resizing windows by name, so I don’t know if that part will work.

Because I’m an Applescript noob :wink:

Thanks, that’s the syntax I was looking for!

I feel like I’ll never outgrow noob status. :slight_smile:

j

Ditto. No matter how much you learn, there are always folks who seem to have learned AppleScript right after they finished reading their first book.

Coming from a background of C, Java, Perl et. al., I don’t think I’ll ever be able to fully appreciate Applescript syntax. Nor use, for the most part, I guess… I just tried to subscript a list item with every sort of bracket and brace available.

Noob for life :wink:

The Satimage.osax (free) has array capability. Most of us just use lists which have a number of features that help. See these articles by Kai Edwards and Nigel Garvey.