Hi Shane,
How I can call during the application launching handler a splash screen.
On page 59 of your book there is a good example about when the sheet is invoked by button.
In my case I want that app is launched, the mainWin appear and immediately a sheet (with logo, version, etc…) appear over the mainWin, wait 4 sec and after automatically close.
In ASS is simple (display panel window “blabla” attached to window main and delay 4 seconds…
using ASOC?
Alex
Try something like this:
tell current application's NSApp to beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(customWindow, mainWindow, me, "", missing value)
tell current application's NSThread to sleepForTimeInterval_(4)
tell customWindow to orderOut_(me) -- now close the sheet
You need to put it somewhere like an on applicationDidFinishLaunching_ handler.
Because you’re closing straight after the delay, you don’t need customSheetDidEnd_returnCode_contextInfo_, which means you don’t need to add the protocol file to your project (unless you show other sheets).
Actually, blocking for 4 seconds like that is not a good idea. Better to do something like this:
tell current application's NSApp to beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(customWindow, mainWindow, me, "", missing value)
performSelector_withObject_afterDelay_("thatsEnough", missing value, 4)
on thatsEnough()
tell customWindow to orderOut_(me) -- now close the sheet
end thatsEnough
As usually many, many, many, thanks.
I suggest you to include this in the future pages of your wonderful book.
I hope also that Xcode 4 will simplify some “complicated” ways. I hope that Apple engineers expand ASOC bridge.
Alex
Hi Shane,
I put the
tell current application’s NSApp to beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(splashWindow, mainWindow, me, “”, missing value)
performSelector_withObject_afterDelay_(“closeSplash”, missing value, 3
in applicationWillFinishLaunching_
All works good.
When the app is launched the mainWin appear, the sheet appear and after 3 second is closed.
But I would like also to connect the “About my App…” to show the sheet.
So I created a handler called showSplash_(sender) connected to the About my App menu.
on showSplash_(sender)
log “OK”
tell current application’s NSApp to beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(splashWindow, mainWindow, me, “”, missing value)
performSelector_withObject_afterDelay_(“closeSplash”, missing value, 1)
end showSplash_
When I run the app and choose About my app… the log is stamped but the sheet don’t appear. I miss something?
Also the same routine showSplash_(sender) should be called from applicationWillFinishLaunching_
Usually I did this in AppleScript Studio. But how I can do this in ASOC?
Thanks in advance
Alex
It looks like using a selector of “” might be being too clever. I get it to work once, and then stop. So the solution is to do the full thing: include the protocol and include the customSheetDidEnd_returnCode_contextInfo_ handler:
on showCustomSheet_(sender)
tell current application's NSApp to beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(customWindow, mainWindow, me, "customSheetDidEnd:returnCode:contextInfo:", missing value)
performSelector_withObject_afterDelay_("thatsEnough", missing value, 1)
end showCustomSheet_
on thatsEnough()
set returnCode to 0 -- whatever
tell current application's NSApp to endSheet_returnCode_(customWindow, returnCode)
end thatsEnough
-- called when window is closed
on customSheetDidEnd_returnCode_contextInfo_(theSheet, returnCode, unUsed)
tell theSheet to orderOut_(me) -- now close the sheet
end customSheetDidEnd_returnCode_contextInfo_
Hi,
thanks for your post but I think to have not undesrtood.
In ASS I use the following simple script:
on choose menu item theObject
set objectName to name of theObject
if objectName is “mAbout” then
ShowPanel()
ClosePanel()
end if
end choose menu item
on will finish launching theObject
ShowPanel()
ClosePanel()
end will finish launching
on ShowPanel()
display panel window “myPanel” attached to window “mainWin”
end ShowPanel
on ClosePanel()
delay 3
close panel window “myPanel”
end ClosePanel
Code is simple. When app is launched the panel sheet appear, wait 3 sec and after is closed. The same when I choose About my app from menu.
But I can’t reproduce using ASOC. The handler with _(sender) can be connected to the menu but what I need to call when the app is launched? I can’t call the handler with _(sender)
Alex
on applicationWillFinishLaunching_(notif)
showCustomSheet_(me)
end applicationWillFinishLaunching_
The sender is the thing doing the calling of the handler – in this case “me”. But because the handler never uses the sender variable, it can be pretty much anything in this case.
You guys are psychic – the sender stuff is something I’ve been writing about. Stay tuned for a couple of days…
So if you go to http://www.macosxautomation.com/applescript/apps/errata.html, you will see a link to a page with an explanation of sender, among other things.