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.
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 "http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html" 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).
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!
Version for checking for installed osaxens in application bundles.
Removed a minor bug in the script above.
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 "http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html" 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
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?
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).
The question is for Leopard, what it takes.
It has been possible to include scripting additions since Panther according to this post.
The fastest way to check for Osaxen in general is to do something like this:
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:
on satimageOsaxInstalled()
try
set _text to "test"
find text "test" in _text
true
on error
false
end try
end satimageOsaxInstalled
satimageOsaxInstalled()