My problem is that the panel won’t open, and so I don’t see the progress bar.
All I am looking for is the panel to come down, show the progress bar turning, then for the panel to go away when iCal is done adding the event. This is the entire script, but I’m not sure I have everything right in Interface builder. The Documentation for display mentioned clicking panel ended, but then further down it looked like you didn’t need it.
I’m confused.
-- +Event.applescript
-- +Event
-- Created by Michael Ewald on 6/26/06.
-- Copyright 2006 Michael Ewald. All rights reserved.
load panel "statusPanel" from nib "statusPanel"
on clicked theObject
-- Get & Format form items
set eventTitle to contents of text field "eventTitle" of window "main" as string
set eventLocation to contents of text field "eventLocation" of window "main" as string
set EventNotes to contents of text view "eventNotesText" of scroll view "eventNotesScroll" of window "main"
set allDay to state of button "allDay" of window "main"
set startDate to current date
set startDate to content of control "startDate" of window "main"
set endDate to content of control "endDate" of window "main"
-- Make Event
start progress indicator "statusBar" of window "statusPanel"
try
start progress indicator "statusBar" of window "statusPanel"
display "statusPanel" attached to window "main"
tell application "iCal"
set theCalName to "AppleScript Test"
set theCal to calendar theCalName
if allDay is equal to 1 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, allday event:true, description:EventNotes}
else if allDay is equal to 0 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, start date:startDate, end date:endDate, description:EventNotes}
end if
end tell
-- reset form
set the contents of text field "eventTitle" of window "main" to ""
set the contents of text field "eventLocation" of window "main" to ""
set contents of text view "eventNotesText" of scroll view "eventNotesScroll" of window "main" to ""
set state of button "allDay" of window "main" to 0
set currentDate to current date
set currentDatePlus to (current date) + 1 * hours
-- Update Times
set content of control "startDate" of window "main" to currentDate
set content of control "endDate" of window "main" to currentDatePlus
on error
display alert "There was a problem!"
end try
close panel "statusPanel"
end clicked
Model: MacBook Pro 2.16 120gb hard drive
Browser: Safari 416.13
Operating System: Mac OS X (10.4)
May be we can get help from some savvier guys in this forum.
I, too, tried to use the Display Panel example but, just like you, I can’t find get the panel to display as attached to the active window. When I use the keyword “display” and have the panel attached to the active window, nothing comes out. When i use “show”, the panel shows up but only if it is not attached to the active window. When I try to attach it to the active window, nothing goes.
I am not sure what’s wrong but I am continually experimenting and if I find a solution, I will post it here.
Meanwhile, please do the same and let’s wish us good luck.
After much trial and error, and using the Display Panel example in Xcode, here is a very simple version of a panel attached to the window “main”.
property panelWindow: missing value
property attachThisPanel: 1
on clicked theObject
if the name of theObject is "showPanel" then
if attachThisPanel is equal to 1 then
load nib "warningPanel"
if panelWindow is missing value then
set panelWindow to "windowPanel"
display panel window "windowPanel" attached to window "main"
end if
end if
end if
if the name of theObject is "Quit" then
close panel window "windowPanel"
quit
end if
end clicked
Note that in this case, I used two nibs (main and warningPanel that is separately loaded by the script).
In the main nib, there is only one window “main” that has just one button “showPanel”. And, in the attached panel itself, there is only one window (named "windowPanel) with a fixed text and one button to close the panel and quit.
I think that the key is to declare the attached panel behaviour as a property and then test that condition in the script. In the simple code above, note that this property is set to integer 1 (if 0, then the panel is not attached). Fredo used the boolean property in his button, as you might have noticed.
As regards the advantage of using one vs many nibs, that depends on the complexity of the program. The more complex it is, the greater the need for multiple nibs. Otherwise, it is very difficult to locate some objects in your IB in case you may need to work on them. Simple programs do not normally need multiple nibs though that would still depend on personal preference.
OK, I hope this gets you going lx-88. I am on my way to using this now myself.
I am afraid you’d have to have a way to activate the panel attached to the active window. If you don’t want it to be triggered by a button click, you will have to code something in your script that would activate the panel window, something like a condition that must be met before your panel is displayed, complete with the progress bar.
Hypothetically, the test may go like this: if thisCondition is true, then display panel window “myPanel” attached to window “main”, else do something else. Initially, you may set thisCondition to false in the property section.
This technique should eschew the use of a button to activate the panel.
I think that is possible with my original code. I want to avoide a button that says Open Panel, but instead do other tasks. Take a look at my first post in this thread, I think that the button click to write a new event to iCal would work as the same button to open the panel? That’s basically all I’m looking for, to do a task when I push a button, and while it’s doing that task display a panel to show that something is happening.
Is there anything I need to do in Interface Builder besides build the panel?
I don’t think you need to do anything else in the IB. As long as you have a panel that can be attached to an active window and it is working perfectly, the only thing you would need is a way to activate that panel, either using a button click (which you do not like to do) or by using a conditional statement in your script which you should be able to do easily. That should suffice to be able to display your panel with your progress bar.
After the task is finished, again you can test a condition in your script so that when that condition is met (for instance, a task is completed) you can again use a script code to close the attached panel. All these can be done without buttons.
I looked at and copied the 2nd example that Fredo d;o) posted and while his script runs fine, mine does not. I looked at the documentation for Applescript studio and it looks like display panel is now just display after Applescript studio 1.1. It doesn’t work for me either way.
PLEASE have a look at my code and tell me what’s wrong. Thanks so much!
-- +Event.applescript
-- +Event
-- Created by Michael Ewald on 6/26/06.
-- Copyright 2006 Michael Ewald. All rights reserved.
on clicked theObject
-- Get & Format form items
set eventTitle to contents of text field "eventTitle" of window "main" as string
set eventLocation to contents of text field "eventLocation" of window "main" as string
set EventNotes to contents of text view "eventNotesText" of scroll view "eventNotesScroll" of window "main"
set allDay to state of button "allDay" of window "main"
set startDate to current date
set startDate to content of control "startDate" of window "main"
set endDate to content of control "endDate" of window "main"
-- Make Event
display panel window "statusWindow" attached to window "main"
tell window "statusWindow"
tell progress indicator "statusBar" to start
end tell
delay 0.5
try
tell application "iCal"
launch
set theCalName to "AppleScript Test"
set theCal to calendar theCalName
if allDay is equal to 1 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, allday event:true, description:EventNotes}
else if allDay is equal to 0 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, start date:startDate, end date:endDate, description:EventNotes}
end if
end tell
-- reset form
set the contents of text field "eventTitle" of window "main" to ""
set the contents of text field "eventLocation" of window "main" to ""
set contents of text view "eventNotesText" of scroll view "eventNotesScroll" of window "main" to ""
set state of button "allDay" of window "main" to 0
set currentDate to current date
set currentDatePlus to (current date) + 1 * hours
-- Update Times
set content of control "startDate" of window "main" to currentDate
set content of control "endDate" of window "main" to currentDatePlus
on error
display alert "There was a problem!"
end try
tell progress indicator "statusBar" of window "statusWindow" to stop
close panel window "statusWindow"
end clicked
on clicked theObject
-- If you have many operations in the same window, use syntax "tell" like target
-- It is not really necessary, but, with this syntax, your script is more easy to write and more clear to read.
tell window "main"
-- Get & Format form items
set eventTitle to contents of text field "eventTitle" as string
set eventLocation to contents of text field "eventLocation" as string
set EventNotes to contents of text view "eventNotesText" of scroll view "eventNotesScroll"
set allDay to state of button "allDay"
set startDate to current date
set startDate to content of control "startDate"
set endDate to content of control "endDate"
end tell
-- Start progress before display progress window
tell progress indicator "statusBar" of window "statusWindow" to start
-- Display progress window
display panel window "statusWindow" attached to window "main"
-- You can also use the "display window" syntax, without the "panel" class
-- display window "statusWindow" attached to window "main"
-- Attetion, in both cases, it is necessary that your window is of type "Panel"
-- ("NSPanel" in IB inspector window title), if not, that will not works
try
-- Launch application iCal
tell application "iCal" to launch
-- Delay for wait iCal
delay 0.5
tell application "iCal"
set theCalName to "AppleScript Test"
set theCal to calendar theCalName
if allDay is equal to 1 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, allday event:true, description:EventNotes}
else if allDay is equal to 0 then
make new event at end of calendar theCalName with properties {summary:eventTitle, location:eventLocation, start date:startDate, end date:endDate, description:EventNotes}
end if
end tell
on error
-- To activate your application after an error in iCal
tell me to activate
-- Close progress window
close panel window "statusWindow"
-- Display alert after close progress window
-- Is not necessary, but, in this way, you can attach it to window "main"
display alert "There was a problem!" -- attached to window "main"
end try
-- To activate your application, it is not necessary here, juste by precaution
tell me to activate
-- Syntax "tell" for some changes in the same window
tell window "main"
-- reset form
set the contents of text field "eventTitle" to ""
set the contents of text field "eventLocation" to ""
set contents of text view "eventNotesText" of scroll view "eventNotesScroll" to ""
set state of button "allDay" of window "main" to 0
set currentDate to current date
set currentDatePlus to (current date) + 1 * hours
-- Update Times
set content of control "startDate" to currentDate
set content of control "endDate" to currentDatePlus
end tell
-- Close progress window
close panel window "statusWindow"
-- Stop progress after close progress window
-- Is not necessary, the progress indicator can stay in start position
tell progress indicator "statusBar" of window "statusWindow" to stop
end clicked