Monday, December 11, 2017

#1 2017-08-29 02:09:34 am

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 21
Website

Odd error arising from Tell command

I have this code:

Applescript:

set app_name to "Safari"
tell application app_name
   set video_URL to URL of current tab of first window
end tell

It pops a syntax error "Expected end of line but found property".  It stops with tab highlighted.

Yet, this code is fine:

Applescript:

tell application "Safari"
   set video_URL to URL of current tab of first window
end tell

Google shows very little on this.  I did find:
http://leancrew.com/all-this/2011/09/ap … weirdness/      and
https://discussions.apple.com/thread/5693069?tstart=0

Solutions abound, but no explanation.


Public servants are people too

Offline

 

#2 2017-08-29 03:02:48 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Odd error arising from Tell command

Application terminology is resolved at compile time. The name of the application must be a constant.

The alternative to tell application "Safari" is

Applescript:

using terms from application "Safari"
   set video_URL to URL of current tab of first window
end using terms from

however "Safari" is required to be a literal string as well.


regards

Stefan

Offline

 

#3 2017-08-29 03:25:50 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4448

Re: Odd error arising from Tell command

Neophyte wrote:

I have this code:

Applescript:

set app_name to "Safari"
tell application app_name
   set video_URL to URL of current tab of first window
end tell

It pops a syntax error "Expected end of line but found property".  It stops with tab highlighted


To enlarge slightly on Stefan's reply, the compiler can't see here that 'current tab' is supposed to be a Safari term, because 'app_name' won't be set until the script's actually run. In the version which does compile, the fact that 'current tab' is a Safari term is explicit in the code.

Last edited by Nigel Garvey (2017-08-29 03:26:48 am)


NG

Offline

 

#4 2017-08-29 07:15:56 am

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

Re: Odd error arising from Tell command

To give Neophyte an answer on how his script would look like:

Applescript:

set app_name to "Safari"
using terms from application "Safari"
   tell application app_name
       set video_URL to URL of current tab of first window
   end tell
end using terms from

Offline

 

#5 2017-08-29 08:46:32 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 21
Website

Re: Odd error arising from Tell command

Many thanks everyone.  This is making sense to me now.

Cheers.


Public servants are people too

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)