[SOLVED] Print result from two functions to console – Stack Overflow

Issue

This Content is from Stack Overflow. Question asked by wit4r7

I’ve created a small script to get the current size and position of a window. Unfortunately, I only can get one result at a time and need to comment/uncomment the other one.

tell application "System Events" to tell process "Toggl Track"
    # get position of window 1
    get size of window 1
end tell

If I uncomment both, I will only get the size.

So, my I tried to write the results in a variable and then log these instead.

tell application "System Events" to tell process "Toggl Track"
    set position to get position of window 1
    set size to get size of window 1
    log position & size
end tell

With this, I get no result at all.

What did I do wrong?



Solution

position and size are part of the terminology of System Events. You cannot use them as variable names. Rename the variables

tell application "System Events" to tell process "Toggl Track"
    set windowPosition to position of window 1
    set windowSize to size of window 1
    log windowPosition & windowSize
end tell 

Regarding the first script, get saves the result of the line in the AppleScript property result and overwrites previous values.


This Question was asked in StackOverflow by wit4r7 and Answered by vadian It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?