Tuesday, June 27, 2017

#1 2017-06-18 10:31:56 am

Brooklynguy
Member
From: New England, USA
Registered: 2013-12-09
Posts: 15

Can Applescript set statements be nested?

Actually Mac OS X 10.11.6 (not an option to pick)

Et Al:
I have a script (converted to an app and put into login items for my account) that I have been using for a few years now.
The app will close all Finder windows and give me two side-by-side each with a different target.

Applescript:


tell application "Finder"
   activate
   close every Finder window
   --
   open home
   tell the Finder window 1
       set toolbar visible to true
       set the sidebar width to 140
       set the current view to list view
       set the bounds to {15, 30, 1265, 1350}
       end tell
   set var_LeftWindow to the target of the front window
   --
   open computer container
   tell the Finder window 1
       set toolbar visible to true
       set the sidebar width to 140
       set the current view to column view
       set the bounds to {1290, 30, 2548, 1350}
   end tell
   set var_RightWindow to the target of the front window
end tell

The two variables are for possible future use.

Can the set statements be nested? I couldn't find anything about this through various forums nor Google.

Hints, thoughts, examples, etc. will be most welcomed.

BG


iMac mid-2011, OS 10.11.6,
iPad 4 9.3.3
iPhone 4s 9.3.1
Medium knowledge of Applsescripting and learning Swift 2 slowly through tutorials.

Offline

 

#2 2017-06-18 07:49:22 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2654

Re: Can Applescript set statements be nested?

Brooklynguy wrote:

Can the set statements be nested? I couldn't find anything about this through various forums nor Google

What do you mean by nested?

You can wrap the set command in an handler to make the (implicit) run handler much simpler.


Applescript:

tell application "Finder"
   activate
   close every Finder window
end tell
set var_LeftWindow to setWindow(false)
set var_RightWindow to setWindow(true)

on setWindow(computerContainer)
   tell application "Finder"
       if computerContainer then
           open computer container
       else
           open home
       end ifa
       tell the Finder window 1
           set toolbar visible to true
           set the sidebar width to 140
           if computerContainer then
               set the current view to column view
           else
               set the current view to list view
           end if
           if computerContainer then
               set the bounds to {1290, 30, 2548, 1350}
           else
               set the bounds to {15, 30, 1265, 1350}
           end if
       end tell
       set var_RightWindow to the target of the front window
   end tell
end setWindow

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.035 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)