I'm trying to learn AppleScript. What you see below a part of my 1st ambitious project. It's modified so that it can be test within the AppleScript editor if you also have an TextEdit window open.
What the script does:
- choose editor from list
- align the two opened windows
My problem:
Aligning the windows works only if I dismiss the variable. As soon as I replace the variable returned from the list (selectedEditor
) with a string tell process "TextEdit"
it works.
I hope someone could spot the error.
Error code from the events log:
System Events got an error: Can’t make {"TextEdit"} into type integer.
Here's the code:
property myEditors : {"TextEdit", "Sublime Text 2"}
set the editorList to myEditors as list
set selectedEditor to choose from list the editorList
set lngWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width")
set lngHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height")
set lngHalf to lngWidth / 2
set lngHeight to lngHeight - 22
tell application id "sevs"
tell process selectedEditor to tell window 1 to set {position, size} to {{lngHalf, 22}, {lngHalf, lngHeight}}
tell process "AppleScript Editor" to tell window 1 to set {position, size} to {{0, 22}, {lngHalf, lngHeight}}
end tell