Scriptable Timer / Stopwatch

Hi Shane,

Why do they make it so complicated? Getting text from text! Anyway, thanks. Need to try that out tomorrow unless can’t sleep.

Editd: think I’m starting to understand it now. Deep stuff.:o

Thanks a lot,
kel

Ok, so first thing tomorrow if I can sleep, is to get the attribute string and the text from that.

Depends on mister sandman :D.

May God be with you,
Goodnight,
kel

Hi Shane,

By Jove, I think it worked now! Amazing what knowledge can do.:smiley:

Used your line:

and I seemed to have gotten text.

Will post the script later.

Edited: btw, here’s the log return if anybody is interested:

Yeah that looks more like text.

Thanks a lot,
kel

Yep, it worked. Here’s the return from the tester :smiley:

Hi,

I posted the solution that I was thinking about all night, but deleted it because one part was forgotten. Anyway, to make a long story short, think I have a solution with the split/pause stopwatch. Mainly, theres a lot of toggling (i.e. changing button names and content field text). It looks like it might work.

Edited: btw, here’s a couple of things. Note that the text “Click here to toggle split/pause.” fits on one line. Another thing that solved it is the states of buttons only need to change once. For instance if you look at the Start/Stop button, once it changes from start to stop, then there is no resetting of the toggled split/pause button (i.e. the content field). This two buttons can’t be changed after they are set. That was the main solution to the puzzle of the limitations. It’s like you’re switching between meanings of the buttons according to the state of the other button and what the user chooses! :smiley:

I have the hardest time remembering what the buttons mean on a watch, but computers have more tools. :slight_smile:

Later,
kel

Hello kel, I am glad you figured it all out.

My “model” of a stopwatch uses states, “Stopped” is when it is not running, pressing start, pushes it over into the “Running” state, from the “Running” state, it can become “Stopped” or “Paused”, when it is “Paused”, it can become “Running” and “Stopped”, when it is “Stopped”.

The buttons switches according to the states. by the way, I am done with the code now, over in Code Exchange, you may want to read it, it should be considerably more readable by now. It also has a service that doesn’t leak memory, and an app so you can invoke it from the Dock, or Spotlight. I think you should be able to scavenge the run handler, and put your own notifications into it.

And I do hope you post your solution when you have it working, it will be interesting to look at. :slight_smile:

Hi McUsr,

Maybe I got the solution in my half sleep from skimming through your code! Then, it awoke from my subconscious mind! :cool: But then, I was trying to think on my own plane from the template. Who knows?

I’m almost finished though. Just taking out some of things from the template that is not needed and filling the subroutines with relevant stuff.

After it’s done, I want to convert it out of Xcode into AppleScript.

The things that still bug me are the close button and the user getting the split times. I might need to look more into how you handled that.

Great mind,
kel

Ps. did you see the Nova documentary on mystery of mathematics or something like that. It was very interesting how they covered all the realms of reality and math. It was a good review.

gl,
kel

Here’s some of the very raw flow of things in the work in progress in translating the template:

script AppDelegate
    
    -- IBOutlets
    property theWindow : missing value
    
    property parent : class "NSObject"
    property myNotification : missing value
    property notificationCount: 0
    property splitPauseSetting: "split"
    property startStopState: "Start"
    
    on applicationWillFinishLaunching_(aNotification)
        -- initialize
        return
    end applicationWillFinishLaunching_
    
    -- reopen handler
    on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        my applicationDidFinishLaunching_(missing value)
        return NO
    end applicationShouldHandleReopen_hasVisibleWindows_
    
    -- main
    on applicationDidFinishLaunching_(aNotification)
        -- set the delegate to script
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
        -- get current date and target date
        set sentDate to current application's NSDate's |date|()
        set sentDateAsString to my formatDate_(sentDate,1,2)
        set numSeconds to 5
        set targetDate to current application's NSDate's dateWithTimeInterval_sinceDate_(numSeconds,sentDate)
        -- make user info NSDictionary
        set notificationCount to notificationCount + 1
        set nsDict to current application's NSDictionary's dictionaryWithObjectsAndKeys_(notificationCount, "notificationIndex", sentDateAsString, "sentDate", "value3", "key3", missing value)
        -- send notification to NSUserNotificationCenter
        my sendNotification_("Stopwatch2","Click here to toggle split/pause.","Current setting: " & splitPauseSetting,startStopState,"Cancel",targetDate,"Boing",nsDict)
        say "Notification sent."
        return
    end applciationDidFinishLaunching_
    --
    
    -- format NSDate to string using styles
    -- 0 = none, 1 = short, 2 = med, 3 = long, 4 = full
    on formatDate_(aNSDate, aDateStyle, aTimeStyle)
        set myFormatter to current application's NSDateFormatter's alloc()'s init()
        myFormatter's setDateStyle_(aDateStyle)
        myFormatter's setTimeStyle_(aTimeStyle)
        set formattedDate to myFormatter's stringFromDate_(aNSDate)
        return formattedDate
    end formatDate_
    
    -- method for sending a notification
    on sendNotification_(aTitle, aSubtitle, aMessage, aActionButtonTitle, aOtherButtonTitle, aDeliveryDate, aSound, aDict)
        -- make the notification
        set myNotification to current application's NSUserNotification's alloc()'s init()
        set myNotification's title to aTitle
        set myNotification's subtitle to aSubtitle
        set myNotification's informativeText to aMessage
        set myNotification's actionButtonTitle to aActionButtonTitle
        set myNotification's otherButtonTitle to aOtherButtonTitle
        set myNotification's deliveryDate to aDeliveryDate
        set myNotification's soundName to aSound
        set myNotification's userInfo to aDict
        --set myNotification's hasReplyButton to true
        -- schedule the notification
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's scheduleNotification_(myNotification)
        return
    end sendNotification_
    
    -- delegate instance methods
    -- force presentation for when application process is frontmost
    on userNotificationCenter_shouldPresentNotification_(aCenter, aNotification)
        return yes
    end userNotificationCenter_shouldPresentNotification_
    
    -- deliver
    on userNotificationCenter_didDeliverNotification_(aCenter, aNotification)
        say "Notification Delivered"
        return
    end userNotificationCenter_didDeliverNotification_
    
    -- user activation
    on userNotificationCenter_didActivateNotification_(aCenter, aNotification)
        say "Notification Activated"
        -- 0    none (does not work)
        -- 1    contents clicked
        -- 2    action button clicked
        -- 3    additional button clicked
        -- Gets user entry from notification's text field
        set userActivationType to (aNotification's activationType) as integer
        -- note: eliminated option 0 because there was no way to get reply besides monitoring notification window
        -- use action button 2 to get reply for close or quit
        if userActivationType is 1 then
            say "contents clicked"
            my contentsClicked_(aNotification)
            else if userActivationType is 2 then
            say "action button clicked"
            my actionButtonClicked_(aNotification)
            else if userActivationType is 3 then -- userActivationType is 3
            say "user activation type is 3"
            my replyButtonClicked_(aNotification)
            else -- if userActivationType is 4 then -- never happens as it is never 0 or 4
            beep 3
        end if
        return userActivationType
    end userNotificationCenter_didActivateNotification_
    
    -- new plan for close button:
    --  keep the application open for 5 minutes
    --  after 5 minutes, check if there are scheduled notificaitons and delivered notifications
    --  if no then quit
    --  otherwise, there are either scheduled notificaitons or delivered notifications
    
    -- user subroutines
    
    -- quick toggle
    -- need to change to boolean toggle
    on contentsClicked_(aNotification)
        -- toggle split/pause variable
        if splitPauseSetting is "split" then
            set splitPauseSetting to "pause"
        else
            set splitPauseSetting to "split"
        end if
        -- check state of start/stop button
        -- if state is start, then remove this notification and resend with new split/pause setting
        
        return
    end contentsClicked_
    
    -- gets user reply in text field
    -- not used in stopwatch
    -- later used for egg timer
    on replyButtonClicked_(aNotification)
        -- set userTextEntry to (aNotification's response) as text
        set userTextEntry to (aNotification's response()'s |string|()) as text
        return true
    end replyButtonClicked_
    
    -- gets user info and deletes delivered notification from Notification Center
    -- not needed for stopwatch
    on actionButtonClicked_(aNotification)
        -- delete the notification and send a new one (or some other action)
        -- first get info on notification
        set theInfo to aNotification's userInfo
        set theValue to theInfo's valueForKey_("notificationIndex")
        say (theValue as string)
        -- delete notification from notification center
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's removeDeliveredNotification_(aNotification)
        -- send a new notification
        my applicationDidFinishLaunching_(missing value)
        return
    end actionButtonClicked_
    
    --
    
    -- quit app if user presses close button
    on applicationShouldTerminateAfterLastWindowClosed_()
        return true
    end applicationShouldTerminateAfterLastWindowClosed_
    
    -- quit
    on applicationShouldTerminate_(sender)
        -- Insert code here to do any housekeeping before your application quits
        return current application's NSTerminateNow
    end applicationShouldTerminate_
    
    
end script

Eliminated some stuff already, but still going through the script and adding stuff. The main thing is how it starts and should continue like the flow chart in my brain. Still working on it.

Have a good day,
kel

Hello.

I don’t know if this helps at this stage, but I mocked up a state diagram for you.

Imagine the different dialogs between the states, or notifications for that matter. Maybe one scheme that would help you, is that you also keep an internal state, and then you “query the state”, and do the action directly, or you use a "clock object that I do, and simply passes the button over to it, so that you have all the logic in the clock object. That is at least ways to do it, that should be fairly simple, yet provide a good overview of what happens at all times.

I have a simpler model, than you with respect to “split time”: The current state is stopped, when the user don’t cancel a dialog, that way, I always stop the correct “timer”, the other was stopped before the last one got activate. This is however not the same as “split seconds” on a stopwatch, where you take an “intermediary time”.

By the way, you should really google Patek Phillipe Grandmaster video. :slight_smile:

Hi McUsr,

I don’t think like you guys, but go step by step. That may be why I’m so slow. Different learning styles. But, thanks anyway. I got up to this point now in the step by step approach:

script AppDelegate
    
    -- IBOutlets
    property theWindow : missing value
    
    property parent : class "NSObject"
    property myNotification : missing value
    property notificationCount: 0
    property splitPauseSetting: "split"
    property startStopState: "Start"
    
    on applicationWillFinishLaunching_(aNotification)
        -- initialize
        return
    end applicationWillFinishLaunching_
    
    -- reopen handler
    on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        my applicationDidFinishLaunching_(missing value)
        return NO
    end applicationShouldHandleReopen_hasVisibleWindows_
    
    -- main
    on applicationDidFinishLaunching_(aNotification)
        -- set the delegate to script
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
        -- get current date and target date
        set sentDate to current application's NSDate's |date|()
        set sentDateAsString to my formatDate_(sentDate,1,2)
        set numSeconds to 5
        set targetDate to current application's NSDate's dateWithTimeInterval_sinceDate_(numSeconds,sentDate)
        -- make user info NSDictionary
        set notificationCount to notificationCount + 1
        set nsDict to current application's NSDictionary's dictionaryWithObjectsAndKeys_(notificationCount, "notificationIndex", sentDateAsString, "sentDate", "value3", "key3", missing value)
        -- send notification to NSUserNotificationCenter
        my sendNotification_("Stopwatch2","Click here to toggle split/pause.","Current setting: " & splitPauseSetting,startStopState,"Cancel",targetDate,"Boing",nsDict)
        say "Notification sent."
        return
    end applciationDidFinishLaunching_
    --
    
    -- format NSDate to string using styles
    -- 0 = none, 1 = short, 2 = med, 3 = long, 4 = full
    on formatDate_(aNSDate, aDateStyle, aTimeStyle)
        set myFormatter to current application's NSDateFormatter's alloc()'s init()
        myFormatter's setDateStyle_(aDateStyle)
        myFormatter's setTimeStyle_(aTimeStyle)
        set formattedDate to myFormatter's stringFromDate_(aNSDate)
        return formattedDate
    end formatDate_
    
    -- method for sending a notification
    on sendNotification_(aTitle, aSubtitle, aMessage, aActionButtonTitle, aOtherButtonTitle, aDeliveryDate, aSound, aDict)
        -- make the notification
        set myNotification to current application's NSUserNotification's alloc()'s init()
        set myNotification's title to aTitle
        set myNotification's subtitle to aSubtitle
        set myNotification's informativeText to aMessage
        set myNotification's actionButtonTitle to aActionButtonTitle
        set myNotification's otherButtonTitle to aOtherButtonTitle
        set myNotification's deliveryDate to aDeliveryDate
        set myNotification's soundName to aSound
        set myNotification's userInfo to aDict
        --set myNotification's hasReplyButton to true
        -- schedule the notification
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's scheduleNotification_(myNotification)
        return
    end sendNotification_
    
    -- delegate instance methods
    -- force presentation for when application process is frontmost
    on userNotificationCenter_shouldPresentNotification_(aCenter, aNotification)
        return yes
    end userNotificationCenter_shouldPresentNotification_
    
    -- deliver
    on userNotificationCenter_didDeliverNotification_(aCenter, aNotification)
        say "Notification Delivered"
        return
    end userNotificationCenter_didDeliverNotification_
    
    -- user activation
    on userNotificationCenter_didActivateNotification_(aCenter, aNotification)
        say "Notification Activated"
        -- 0    none (does not work)
        -- 1    contents clicked
        -- 2    action button clicked
        -- 3    additional button clicked
        -- Gets user entry from notification's text field
        set userActivationType to (aNotification's activationType) as integer
        -- note: eliminated option 0 because there was no way to get reply besides monitoring notification window
        -- use action button 2 to get reply for close or quit
        if userActivationType is 1 then
            say "contents clicked"
            my contentsClicked_(aNotification)
            else if userActivationType is 2 then
            say "action button clicked"
            my actionButtonClicked_(aNotification)
            else if userActivationType is 3 then -- userActivationType is 3
            say "user activation type is 3"
            my replyButtonClicked_(aNotification)
            else -- if userActivationType is 4 then -- never happens as it is never 0 or 4
            beep 3
        end if
        return userActivationType
    end userNotificationCenter_didActivateNotification_
    
    -- new plan for close button:
    --  keep the application open for 5 minutes
    --  after 5 minutes, check if there are scheduled notificaitons and delivered notifications
    --  if no then quit
    --  otherwise, there are either scheduled notificaitons or delivered notifications
    
    -- user subroutines
    
    -- quick toggle
    -- need to change to boolean toggle
    on contentsClicked_(aNotification)
        -- toggle split/pause variable
        if startStopState is "Start" then
            if splitPauseSetting is "split" then
                set splitPauseSetting to "pause"
            else
                set splitPauseSetting to "split"
            end if
        else -- startStopState is "Stop"
            if splitPauseSetting is "split" then
                say "splitting"
            else
                say "pausing"
            end if
        end if
        -- check state of start/stop button
        -- if state is start, then remove this notification and resend with new split/pause setting
        
        return
    end contentsClicked_
    
    -- gets user reply in text field
    -- not used in stopwatch
    -- later used for egg timer
    on replyButtonClicked_(aNotification)
        -- set userTextEntry to (aNotification's response) as text
        set userTextEntry to (aNotification's response()'s |string|()) as text
        return true
    end replyButtonClicked_
    
    -- action button state is "stop" or "start"
    on actionButtonClicked_(aNotification)
        -- delete the notification and send a new one (or some other action)
        if startStopState is "Start" then
            -- first toggle startStopeState
            set startStopState to "Stop"
        else -- user chose stop
            say "user chose stop"
        -- delete notification from notification center
        (*
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's removeDeliveredNotification_(aNotification)
         *)
        end if
        -- send a new notification
        my applicationDidFinishLaunching_(missing value)
        return
    end actionButtonClicked_
    
    --
    
    -- quit app if user presses close button
    on applicationShouldTerminateAfterLastWindowClosed_()
        return true
    end applicationShouldTerminateAfterLastWindowClosed_
    
    -- quit
    on applicationShouldTerminate_(sender)
        -- Insert code here to do any housekeeping before your application quits
        return current application's NSTerminateNow
    end applicationShouldTerminate_

end script

Iv’e got the action button to change to Stop! That’s a big hurdle for me.

Once in a while I do have these streaks of genius though. I think it happened one day when I was young and riding skateboard on these cliffs. I was about 17 years old and riding this big hill. Then all of a sudden the wheels locked. My body was horizontal to the ground and I just went straight down and hit the back of my head. Think I knocked out for a few minutes and when I woke my friend was looking me in the face. That was just one of the many times I almost died.

But, anyway, what were we talking about? :smiley:

Glad you made it.

We all do work through stuff step by step I guess, when entering unknown territory, (it all depends on how unknown it is, personally I find it best sometimes, to make call after call work, and then also add the steps necessary as I go along when I learn the technology, (most people do that I believe), because merely reading up on a subject, if you haven’t got anything that resembles it quite a bit internalized up front, then the sound practice is to both try to make it work, and read up at the same time. :slight_smile:

But later on, we structure the stuff, so that the code becomes more maintainble, and graspable, the nice sideffect, is that it becomes easy to intergrate with the rest of our goal. On superb technique, is to see to that everything is encapsulated, and that the different objects, just shares data through methods. (It is not set in stone.)

Restructuring code becomes easier with practice. And then you in the end end up with programs that are both easy to read, and to maintain/develop further.

I am not overbearing in anyway here, I am just telling you that you don’t deviate that much, and that lots of code are originated the same way, it is what happens afterwards that is the big difference. And sometimes, it don’t happen too, (the restructirng), especially in AppleScript because it is really slow, and if you are to iterate over a lot of items, then a procedural (step-by-step) approach is better.

It is very late here. Tomorrow. :slight_smile:

Hi McUser,

That’s because I’m anal retentive. :smiley: Any change and I gotta go all over again step by step. It’s a pain, but sometimes you find changes and you have to rewrite some things all over again to get the max. Almost from scratch sometimes. But, as I said everybody has their own way of doing things.

When I’m done I can sleep. Darn, haven’t slept for 2 days. The mind just keeps going.

Edited: i.e. haven’t slept good for 2 days.

Edited: btw: it’s like deja vu all over again!

Have a nice day,
kel

Hi McUsr,

I’m so confused! :smiley: Didn’t follow my own advice to start from scratch and go step by step. Instead, I tried to just modify the template and that what is causing the confusion. Need to start all over again. Although, I do have the algorithm in my mind.

Later,
kel

This is a good starting template for me! :slight_smile:

script AppDelegate
	property parent : class "NSObject"
	
	-- IBOutlets
	property theWindow : missing value
	
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
    
    -- reopen handler
    on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        my applicationDidFinishLaunching_(missing value)
        return NO
    end applicationShouldHandleReopen_hasVisibleWindows_
    
    -- main
    on applicationDidFinishLaunching_(aNotification)
        -- set the delegate to script
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
        return
    end applciationDidFinishLaunching_
	
    -- quit app if user presses close button
    on applicationShouldTerminateAfterLastWindowClosed_()
        return true
    end applicationShouldTerminateAfterLastWindowClosed_
    
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

Bare bones with the main subroutines. What I think was mixing me up man was the variables and all the extraneous stuff. Not sure.

Later,
kel

Ok, first step finished. Created the first notification:

script AppDelegate
	property parent : class "NSObject"
	
	-- IBOutlets
	property theWindow : missing value
    
    -- first step
    -- create the first notification
    property notifTitle: "Notification4"
    property notifSubtitle: "Click here to select split/pause."
    property notifInfoText: "Current mode: Split"
    property notifActionButtonTitle: "Start"
    property notifOtherButtonTitle: "Cancel"
    property notifSound: "Boing"
    -- now every text field of the notification is filled
    -- next is boolean variables, but check out how it looks in a notification
    -- send the notification after finished launching
    
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
    
    -- reopen handler
    on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        my applicationDidFinishLaunching_(missing value)
        return NO
    end applicationShouldHandleReopen_hasVisibleWindows_
    
    -- main
    on applicationDidFinishLaunching_(aNotification)
        -- set the delegate to script
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
        my sendNotification_(notifTitle,notifSubtitle,notifInfoText,notifActionButtonTitle,notifOtherButtonTitle,notifSound)
        return
    end applciationDidFinishLaunching_

    -- method for sending a notification
    on sendNotification_(aTitle, aSubtitle, aInfoText, aActionButtonTitle, aOtherButtonTitle, aSound)
        -- make the notification
        set myNotification to current application's NSUserNotification's alloc()'s init()
        set myNotification's title to aTitle
        set myNotification's subtitle to aSubtitle
        set myNotification's informativeText to aInfoText
        set myNotification's actionButtonTitle to aActionButtonTitle
        set myNotification's otherButtonTitle to aOtherButtonTitle
        set myNotification's soundName to aSound
        -- schedule the notification
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's scheduleNotification_(myNotification)
        return
    end sendNotification_
	
    -- quit app if user presses close button
    on applicationShouldTerminateAfterLastWindowClosed_()
        return true
    end applicationShouldTerminateAfterLastWindowClosed_
    
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

We can crunch it up later. Don’t think just do. :smiley:

Edited: remember that you need to set the Notifications preferences in System Preferences to Alerts instead of Banners so that you can see the buttons.

Later,
kel

Hi McUsr,

Added the baroness Delegate instance methods:
[applescriptscript AppDelegate
property parent : class “NSObject”

-- IBOutlets
property theWindow : missing value

-- first step
-- create the first notification
property notifTitle: "Notification4"
property notifSubtitle: "Click here to select split/pause."
property notifInfoText: "Current mode: Split"
property notifActionButtonTitle: "Start"
property notifOtherButtonTitle: "Cancel"
property notifSound: "Boing"
-- now every text field of the notification is filled
-- next is boolean variables, but check out how it looks in a notification
-- send the notification after finished launching

-- step 2
-- user selects start button if user wants split and to start timing
-- else user selects content area to toggle split to pause

-- see Delegate instance methods at bottom

on applicationWillFinishLaunching_(aNotification)
	-- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

-- reopen handler
on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
    my applicationDidFinishLaunching_(missing value)
    return NO
end applicationShouldHandleReopen_hasVisibleWindows_

-- main
on applicationDidFinishLaunching_(aNotification)
    -- set the delegate to script
    current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
    my sendNotification_(notifTitle,notifSubtitle,notifInfoText,notifActionButtonTitle,notifOtherButtonTitle,notifSound)
    return
end applciationDidFinishLaunching_

-- method for sending a notification
on sendNotification_(aTitle, aSubtitle, aInfoText, aActionButtonTitle, aOtherButtonTitle, aSound)
    -- make the notification
    set myNotification to current application's NSUserNotification's alloc()'s init()
    set myNotification's title to aTitle
    set myNotification's subtitle to aSubtitle
    set myNotification's informativeText to aInfoText
    set myNotification's actionButtonTitle to aActionButtonTitle
    set myNotification's otherButtonTitle to aOtherButtonTitle
    set myNotification's soundName to aSound
    -- schedule the notification
    current application's NSUserNotificationCenter's defaultUserNotificationCenter's scheduleNotification_(myNotification)
    return
end sendNotification_

-- DELEGATE INSTANCE METHODS

-- Instruction to force presentation for when application process is frontmost
on userNotificationCenter_shouldPresentNotification_(aCenter, aNotification)
    return yes
end userNotificationCenter_shouldPresentNotification_

-- delivered
on userNotificationCenter_didDeliverNotification_(aCenter, aNotification)
    return
end userNotificationCenter_didDeliverNotification_

-- activated in content field or action button
on userNotificationCenter_didActivateNotification_(aCenter, aNotification)
    return
end userNotificationCenter_didActivateNotification_

-- user subroutines

on contentsClicked_(aNotification)
    return
end contentsClicked_

on actionButtonClicked_(aNotification)
    return
end actionButtonClicked_

-- end user subroutines

-- END DELEGATE INSTANCE METHODS

-- quit app if user presses close button
on applicationShouldTerminateAfterLastWindowClosed_()
    return true
end applicationShouldTerminateAfterLastWindowClosed_

on applicationShouldTerminate_(sender)
	-- Insert code here to do any housekeeping before your application quits 
	return current application's NSTerminateNow
end applicationShouldTerminate_

end script


Forgot to delete some of the old comments, but doing that now. Now we're getting somewhere.

Edited: deleted the one comment I missed to delete.

Edited: now the hard part comes with the logic! :D

Edited: hoping that it's easier now that it's more organized.

Edited: man, maybe I should do it in pencil and paper (the flowchart).

Later,
kel

First pulled the user subroutines out of the delegate methods because it didn’t belong there:

script AppDelegate
	property parent : class "NSObject"
	
	-- IBOutlets
	property theWindow : missing value
    
    -- first step
    -- create the first notification
    property notifTitle: "Notification4"
    property notifSubtitle: "Click here to select split/pause."
    property notifInfoText: "Current mode: Split"
    property notifActionButtonTitle: "Start"
    property notifOtherButtonTitle: "Cancel"
    property notifSound: "Boing"
    -- now every text field of the notification is filled
    -- next is boolean variables, but check out how it looks in a notification
    -- send the notification after finished launching
    
    -- step 2
    -- user selects start button if user wants split and to start timing
    -- else user selects content area to toggle split to pause

    -- see Delegate instance methods at bottom
    
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
    
    -- reopen handler
    on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        my applicationDidFinishLaunching_(missing value)
        return NO
    end applicationShouldHandleReopen_hasVisibleWindows_
    
    -- main
    on applicationDidFinishLaunching_(aNotification)
        -- set the delegate to script
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's setDelegate_(me)
        my sendNotification_(notifTitle,notifSubtitle,notifInfoText,notifActionButtonTitle,notifOtherButtonTitle,notifSound)
        return
    end applciationDidFinishLaunching_

    -- method for sending a notification
    on sendNotification_(aTitle, aSubtitle, aInfoText, aActionButtonTitle, aOtherButtonTitle, aSound)
        -- make the notification
        set myNotification to current application's NSUserNotification's alloc()'s init()
        set myNotification's title to aTitle
        set myNotification's subtitle to aSubtitle
        set myNotification's informativeText to aInfoText
        set myNotification's actionButtonTitle to aActionButtonTitle
        set myNotification's otherButtonTitle to aOtherButtonTitle
        set myNotification's soundName to aSound
        -- schedule the notification
        current application's NSUserNotificationCenter's defaultUserNotificationCenter's scheduleNotification_(myNotification)
        return
    end sendNotification_
    
    -- DELEGATE INSTANCE METHODS
    
    -- Instruction to force presentation for when application process is frontmost
    on userNotificationCenter_shouldPresentNotification_(aCenter, aNotification)
        return yes
    end userNotificationCenter_shouldPresentNotification_
    
    -- delivered
    on userNotificationCenter_didDeliverNotification_(aCenter, aNotification)
        return
    end userNotificationCenter_didDeliverNotification_
    
    -- activated in content field or action button
    on userNotificationCenter_didActivateNotification_(aCenter, aNotification)
        return
    end userNotificationCenter_didActivateNotification_
    
    -- END DELEGATE INSTANCE METHODS
    
    -- user subroutines
    
    on contentsClicked_(aNotification)
        return
    end contentsClicked_
    
    on actionButtonClicked_(aNotification)
        return
    end actionButtonClicked_
    
    -- end user subroutines
	
    -- quit app if user presses close button
    on applicationShouldTerminateAfterLastWindowClosed_()
        return true
    end applicationShouldTerminateAfterLastWindowClosed_
    
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

Hello kel.

That looks very comprehensive to me. :slight_smile:

Have a nice evening.

Hi McUsr,

Yes I had to start al over again. What I’ve found is that in anything that is complicated in logic I need to start from a base way of thinking. Simple stuff. Otherwise, I get into trouble mixing complicated with complicated and end up lost in space.

Btw, I do n’t know if I’ve mentioned this, but i did see the last lunar eclipse and it was beautiful red. There was just a glimpse of it when the clouds separated. I was thinking about this because just saw the documentary on tv.

Step by step inch by inch, getting there.

Have a good one,
kel