AppleScript, manipulate the return value from a one-liner tell-statement, still on the same line?

56 Views Asked by At
tell application "Finder" to get bounds of window of desktop

returns something like

{0, 0, 1440, 900}

How can I do something like

get item 3 of (tell application "Finder" to get bounds of window of desktop)

still in the same line?

The tell statement clearly returns a list but when I try to access it like you access lists, it doesn't work.

3

There are 3 best solutions below

0
matt On

Like this:

tell application "Finder" to get item 3 of (get bounds of window of desktop)
0
wch1zpink On
tell application "Finder" to item 3 of (get bounds of window of desktop)

OR

tell application "Finder" to set thirdItem to item 3 of (get bounds of window of desktop)
2
CJK On

A slightly cleaner way would be to assign each item to a list of variables, like so:

tell application id ("com.apple.finder") ¬
        to set {X, Y, W, H} to the bounds ¬
        of the desktop's window

If you only need W, you can discard the other items by assigning them to a class element, such as null or missing value:

tell application id ("com.apple.finder") ¬
        to set {null, null, W, null} to ¬
        the bounds of the desktop's window