I recently build a “check for update” function.
A function is called from awake from nib from the main script. If a new version is detected on my website it generates a message that a new version is available and you can close the panel or go to the website (and the panel is also closed).
I tried a dialog, a panel and a panel attached to main window.
dialog: The dialog is always displayed twice
panel: The panel is always displayed twice
panel attached to main window: panel is displayed once, but close button activates other button (??)
Below the relevant part of the script. It all works fine apart from the displaying actions.
on awake from nib theObject
FUNC_Version()
end awake from nib
on clicked theObject
if name of theObject is "VOpenWeb" then
open location "http://<URL to my website>"
close panel window "VersionMsg"
else if name of theObject is "VClose" then
close panel window "VersionMsg"
end if
end clicked
on FUNC_Version()
set InfoPath to quoted form of POSIX path of (path to me) & "Contents/Info"
set MyVersion to do shell script "defaults read " & InfoPath & " CFBundleVersion"
try
set WebVersion to do shell script "/usr/bin/curl 'http://<URL to file on my website>/version.txt'"
end try
if WebVersion > MyVersion then
set VersionMsg to "You have version " & MyVersion & ".
Version " & WebVersion & " is now available."
set contents of text field "VersionMsg" of window "VersionMsg" to VersionMsg
if visible of window "VersionMsg" = false then display window "VersionMsg" --attached to window "MainWindow"
(*display dialog VersionMsg buttons {"Get Update", "Close"}
set choice to button returned of result
if choice = "Get Update" then
open location "http://<URL to my website>"
end if*)
end if
end FUNC_Version
No, I have one nib. By now it contains two windows and four panels and a modified menu.
I have 6 scripts. Five scripts use the “awake on nib” to load the shared functions from Functions.applescript. Could that be of influence?
Looks nice, but mine is for the time being simpler and also works fine (apart from the mentioned problem with the panels/dialog)
However, I had the FUNC_Version() as second item in my “awake from nib” after my “my loadscripts()”. I now put it as last item/action in my “awake from nib” (after a bunch of initialisation stuff) and did some further testing. If I now attach it to the main window it does as supposed to and is only called once. As a “non attached” panel or dialog it is still called twice.
I really don’t understand what happens, but it functions now. ergo: I’m happy.
You really put a lot of time in helping others. It is well appreciated. Thanks a lot.