Thursday, July 19, 2018

#1 2012-07-30 07:20:23 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

A general handler for checking if an osax is installed

Hello.

It is just an easy way to figure out if an osax is installed, with the opportunity to point the user to some download page for said osax. The osax that is sought for in the example, doesn't exist.

I stole this ide from Matt-Boy in this post

Applescript:


property scriptTitle : "Test for Osax"

if not (checkforOsax by "Sativmage.osax" against "This script requires satimage.osax You can download Satimage.osax from here:" from "[url]http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html[/url]" for my scriptTitle) then
   tell application "Finder"
       open folder (path to scripting additions folder from local domain)
       open folder (path to downloads folder)
       activate
   end tell
   error number -128
end if


to checkforOsax by OsaxName against eMsg from dlUrl for scriptTitle
   --Make sure XML plug-in is installed. If not, install it.
   local localFol, userFol, found, tBt, go
   set localFol to path to scripting additions folder from local domain as text
   set userFol to path to scripting additions folder from user domain as text
   
   tell application "System Events"
       set found to (exists file (localFol & OsaxName))
       if not found then set found to (exists file (userFol & OsaxName))
   end tell
   if not found then
set go to false
       try
           tell application "SystemUIServer"
               activate
               
               set tBt to button returned of (display dialog eMsg with title scriptTitle default answer dlUrl buttons {"Go", "Ok"} cancel button 2 default button 1 with icon 2)
               set go to (tBt = "Go")
               
           end tell
       end try
       if go then tell application "Safari"
           activate
           open location dlUrl
       end tell
       return false
   else
       return true
   end if
   
end checkforOsax

Edit
It could over course have a more instructive error message, and  be followed up, by opening the appropriate folder in a finder window, the local library IMHO,  and the download folder after the function has failed. In order to ease the process as much as possible!

Not directly opening the url, that gives me the creeps, and a feeling of lack of control. Funny though, I don't even like that behaviour of applications, (if I don't know them well).

Last edited by McUsr (2012-07-30 08:47:59 am)


Mercurial vcs is a joy to use for scripting.

Offline

 

#2 2012-07-30 07:52:05 am

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

Re: A general handler for checking if an osax is installed

How about checking embedded OSAX? When a application bundle contains a 'Scripting Addition' folder, it will be top priority to load this OSAX all over other (user and system) OSAX installed. For distributions I never install an OSAX on workstations but use store them inside the application. On the other hand I'm loading external script objects by webservices or stored on the disk, where some of them need an OSAX and therefore needs to check if they can run properly.

Offline

 

#3 2012-07-30 08:16:27 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: A general handler for checking if an osax is installed

DJ Bazzie Wazzie wrote:

How about checking embedded OSAX? When a application bundle contains a 'Scripting Addition' folder, it will be top priority to load this OSAX all over other (user and system) OSAX installed. For distributions I never install an OSAX on workstations but use store them inside the application. On the other hand I'm loading external script objects by webservices or stored on the disk, where some of them need an OSAX and therefore needs to check if they can run properly.


I really don't know how to load such a scripting addition before any other sought, if not Applescript seeks the scripting additions in that order.

I think you'll have to rework that library for that particular issue. I don't see that problem as something this handler is to take care of really. It is beyond the scope, because this handler is meant to be run from a script. A handler working as you would like, would have to consider its caller, which this handler don't.

I don't even know it if it is possible to consider the caller, if not this handler is embedded in a script library embedded in some code. Then I'd actually have some code embedding this handler, and a property, to  make sure this handler isn't run, or just strip the handler out of the code

Ahh.. and I did make the script more user friendly, giving the option of just pushing the button, to go to the page.

Edit What Bazzie Wazzie wants, is actually a good idea! I live in the belief that a osaxen living in the scripting additons folder of an application bundle will be loaded first, when the applet is running!

This is not on the agenda at the moment, but I'll come back with a version covering this special need. I am sure permissions to use   a scripting addition is easy to get really, if one bother, most require you to say that you use them in your scripts or applications, nowadays, if you are to deliver the osaxens with the applets or scripts, providing for necessary functionality, and this way to obtain scripting additions, says it pretty clearly! smile

Last edited by McUsr (2012-07-30 08:32:08 am)


Mercurial vcs is a joy to use for scripting.


Filed under: osax install

Offline

 

#4 2012-07-30 08:47:22 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: A general handler for checking if an osax is installed

Version for checking for installed osaxens in application bundles. smile

Removed a minor bug in the script above.

Applescript:



property scriptTitle : "Test for Osax"
on run
   
   if not (checkforOsax by "Satimage.osax" against "This script requires satimage.osax You can download Satimage.osax from here:" from "[url]http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html[/url]" for my scriptTitle) then
       set folFound to false
       tell application "System Events"
           
           if exists folder ((path to me as text) & "Contents:Resources:Scripting Additions:") then
               set pxPath to POSIX path of ((path to me as text) & "Contents:Resources:Scripting Additions:")
               set folFound to true
           else if exists folder ((path to me as text) & "Contents:Resources:ScriptingAdditions:") then
               set pxPath to POSIX path of ((path to me as text) & "Contents:Resources:ScriptingAdditions:")
               set folFound to true
           end if
       end tell
       if not folFound then
           set pxFol to POSIX path of ((path to me as text) & "Contents:Resources:")
           
           do shell script "cd " & quoted form of pxFol & " ; mkdir " & quoted form of "Scripting Additions"
           set pxPath to POSIX path of ((path to me as text) & "Contents:Resources:Scripting Additions:")
       end if
       do shell script "cd " & quoted form of pxPath & " ; open . "
       tell application "Finder"
           open folder (path to downloads folder)
           activate
       end tell
       error number -128
   end if
   
end run

to checkforOsax by OsaxName against eMsg from dlUrl for scriptTitle
   
   local localFol1, localFol2, found, tBt, go
   set localFol1 to ((path to me as text) & "Contents:Resources:Scripting Additions:")
   set localFol2 to ((path to me as text) & "Contents:Resources:ScriptingAdditions:")
   
   
   tell application "System Events"
       set found to (exists file (localFol1 & OsaxName))
       if not found then set found to (exists file (localFol2 & OsaxName))
   end tell
   if not found then
       set go to false
       try
           tell application "SystemUIServer"
               activate
               
               set tBt to button returned of (display dialog eMsg with title scriptTitle default answer dlUrl buttons {"Go", "Ok"} cancel button 2 default button 1 with icon 2)
               set go to (tBt = "Go")
               
           end tell
       end try
       if go then tell application "Safari"
           activate
           open location dlUrl
       end tell
       return false
   else
       return true
   end if
   
end checkforOsax



Last edited by McUsr (2012-08-01 12:04:16 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: osaxen installed

Offline

 

#5 2012-07-31 03:12:39 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 545

Re: A general handler for checking if an osax is installed

AFAIK, when you want to use an embedded osax the folder should be called "Scripting Additions", not "ScriptingAdditions".

I remember trying to use an embedded osax, and it wouldn't work, maybe this was in Tiger. Does anybodu know when it became possible to embed osaxen? Did it work as intended from the start?

Offline

 

#6 2012-08-01 01:04:52 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: A general handler for checking if an osax is installed

Hello!

Well, my intentions were right but spelling bad: I had spellled Additions Additons so it didn't work!

But there are no spaces in Scripting Additions when inside an applet!.

I just removed the satimate.osax from My scripting additions folder, and into the ScriptingAddtions folder of my applet, and it worked just fine. smile

And the working version of this code is uploaded to the post above.

Last edited by McUsr (2012-08-01 01:05:30 am)


Mercurial vcs is a joy to use for scripting.


Filed under: osax

Offline

 

#7 2012-08-01 02:54:22 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 545

Re: A general handler for checking if an osax is installed

OK, thank you. My source may have been talking about Tiger only, can't tell.

Offline

 

#8 2012-08-01 05:31:35 am

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

Re: A general handler for checking if an osax is installed

But there are no spaces in Scripting Additions when inside an applet!.


Scripting Additions with a single space works fine as well, no problem.

Offline

 

#9 2012-08-01 05:54:17 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: A general handler for checking if an osax is installed

Hello.

Ok, I seem to remember that that was different some versions ago, maybe that behaviour started with leopard, that means I'll have to search for contents of both folder names!

I'll come back with an updated version. It seems at least what Tiger concerns the name should be ScriptingAdditions according to this link.

I can confirm that Scripting Additons work under Snow Leopard (as do ScriptingAdditions). smile

The question is for Leopard, what it takes.

It has been possible to include scripting additions since Panther according to this post.

Last edited by McUsr (2012-08-01 05:59:45 am)


Mercurial vcs is a joy to use for scripting.


Filed under: scripting additions

Offline

 

#10 2012-08-01 12:03:34 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: A general handler for checking if an osax is installed

Hello!

The code above is updated to consider both foldernames.


Mercurial vcs is a joy to use for scripting.


Filed under: osaxen installed

Offline

 

#11 2014-04-25 12:51:50 pm

ccstone
Member
Registered: 2009-02-07
Posts: 410

Re: A general handler for checking if an osax is installed

The fastest way to check for Osaxen in general is to do something like this:

Applescript:


on scriptingAdditionExists(_name)
   set locScptAddFldr to path to scripting additions from local domain as text
   set sysScptAddFldr to path to scripting additions from system domain as text
   set usrScptAddFldr to path to scripting additions from user domain as text
   set saLocList to {locScptAddFldr, sysScptAddFldr, usrScptAddFldr}
   repeat with i in saLocList
       try
           alias (i & _name)
           return true
       end try
   end repeat
   return false
end scriptingAdditionExists

set _name to "Satimage.osax"

scriptingAdditionExists(_name)

If you just want to know if the Satimage.osax is installed:

Applescript:


on satimageOsaxInstalled()
   try
       set _text to "test"
       find text "test" in _text
       true
   on error
       false
   end try
end satimageOsaxInstalled

satimageOsaxInstalled()

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)