• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help on Checking an applications dictionary for a command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help on Checking an applications dictionary for a command


  • Subject: Re: Help on Checking an applications dictionary for a command
  • From: Adam Wuellner <email@hidden>
  • Date: Wed, 22 Jun 2005 15:40:21 -0500

On 6/22/05, David Siberry <email@hidden> wrote:

> I want to use a try statement because depending on what your default
> browser is depends which command you use. E.g. if your web browser is
> Safari then the function call is "do JavaScript", if its Internet
> Explorer then its "do script".
>
> However, I want to create one script which will check the dictionary
> of the multiple browsers if installed on your machine and try and call
> "do script" if the try fails return false then call "do JavaScript".
> If the command is found then return true.

What's the command for Firefox? Opera?  OmniWeb?  The scripting
terminology is ultimately determined by each app's developer, and as
you've discovered is not guaranteed to remain the same across
applications, even those sharing the same requirements.  This I
mention just to show you that your script may test whether a browser
can be made to execute javascript code with an apple event as
implemented in Safari or IE, but it does not test that ability
_generally_.  Still, it may suit your needs just fine...

> For the "tell application "Safari" for example, the name of the
> browser will be dynamic and passed in as a parameter from my C
> program. This way I can keep the script generic and reusable.
>
> However I am finding that when I compile if the "do script" or "do
> JavaScript" is not in the given applications dictionary, then the
> script will not compile.

Dynamically building and executing applescript code can be
accomplished with the 'run script' command.  Feed it a string (the
applescript code) and it will compile the string and run it.  This
will prevent compilation errors with your main script.  I am not sure
what happens when the string contains syntax errors, though.  You
might have to wrap 'run script ...' in a try block, instead of using
try blocks inside the script to be run.

> tell application "Safari"
>
>       try
>               do script "window.name" (* simple dummy script to test with*)
>               if (do script) then
>                       return true
>               else
>                       return false
>               end if
>       end try
>
>       try
>               do JavaScript "window.name" (* simple dummy script to test with*)
>               if (do JavaScript) then
>                       return true
>               else
>                       return false
>               end if
>       end try

Indeed, that doesn't compile.  Looking at the dictionary for Safari,
it's not at all clear to me that 'do Javascript' has a return value,
or what it would be if it does have one.  It also requires an 'in'
parameter, specifying which document to apply the script to.  You will
need to modify your approach I think.

One way might be to simply try compiling various strings:
try
	run script "tell application \"Safari\" to do script \"window.name\""
	display dialog "'do script' worked"
on error errmsg number errnum
	display dialog "'do script' no worky" & return & errnum & ": " & errmsg
end try

try
	run script "tell application \"Safari.app\" to do JavaScript
\"window.name\" in front document"
	display dialog "'do JavaScript' worked"
on error errmsg number errnum
	display dialog "'do script' no worky" & return & errnum & ": " & errmsg
end try


However, what you're doing is just throwing syntax at an application
and seeing if it sticks.  I have to believe there is a more direct
route...

Take a look here:
<URL:http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptX/Concepts/osa.html#//apple_ref/doc/uid/TP40001571-1153408-BAJIDIFJ>

Do you have any other tools at your disposal? Hamish Sanderson (has)
has written an application (in Python) that displays the scripting
dictionary of applications in a web browser.  His source code is
available. <URL:http://freespace.virgin.net/hamish.sanderson/htmldictionary.html>.

HTH,

Adam W
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Help on Checking an applications dictionary for a command (From: David Siberry <email@hidden>)

  • Prev by Date: Re: Why is copying a file so hard?
  • Next by Date: How to Restart remote 10.3.9 computer with Applescript
  • Previous by thread: Help on Checking an applications dictionary for a command
  • Next by thread: Re: Help on Checking an applications dictionary for a command
  • Index(es):
    • Date
    • Thread