Friday, December 15, 2017

#1 2017-12-02 10:17:07 am

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

issue with 'current date' in archived application

I have an NSdatepicker object with its value bound back to the AppDelegate property theDate like

Applescript:

property theDate: (current date) - (24*60*60)

The goal is to have the date selector preselected to 'yesterday' relative to the time the user runs the application. In Xcode, this works fine. Unfortunately, when I archive the project to a local application it is *apparently?* hard-coding in my 'yesterday' date.

For example, I previously archived a version of the app on 11/28...so, the date selector is preset to 11/27. But, if I ran it today it still shows 11/27.

I just re-archived the app again and it shows 12/1 as expected when run. Tomorrow it should show 12/2, but it will still show  12/1.

Is the some other  way to do what I'm trying to achieve?

Offline

 

#2 2017-12-02 01:55:19 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4454

Re: issue with 'current date' in archived application

Hi.

The value in a property declaration is set when the script's compiled. If you want the value to be the date when the script's run, you have to set it with a command that's executed when the script's run:

Applescript:

property theDate : missing value -- Or any placeholder value.

set theDate to (current date) - days -- 'days' is an AS "constant" equal to 86400.


NG

Online

 

#3 2017-12-02 05:23:41 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: issue with 'current date' in archived application

Thanks for the reply.

What you're saying makes complete sense. But, I'm not sure how to do it.

I'm only able to get the NSdatepicker to take a value I give it from the AppDelegate if I assign it in the property declaration. If I set the property to 'missing value' then, the MainMenu.xib just takes its value from whatever I have in date field under Show Attributes of the element.

I just verified this by putting my theDate 'yesterday' declaration inside the applicationWillFinishLaunching_ handler like so

Applescript:


on applicationWillFinishLaunching_(aNotification)
property theDate: (current date) - (24*60*60)

I verified with a dialog that theDate was properly set. But, the NSdatepicker did not pick it up as it does when assigned in the property declaration.

Catch-22? Or am I missing something? Im still pretty green at this obj-c stuff.

Offline

 

#4 2017-12-03 01:24:15 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: issue with 'current date' in archived application

cudaboy_71 wrote:

Or am I missing something?



You're missing what Nigel said. The property declaration goes at the beginning of the script, and then you set its value in applicationWillFinishLaunching:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2017-12-04 09:10:31 am

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: issue with 'current date' in archived application

You're missing what Nigel said. The property declaration goes at the beginning of the script, and then you set its value in applicationWillFinishLaunching:.



Sorry if I wasn't clear--that's exactly what I said I did in my last post, and explained why it wasn't working.

To help illustrate further, I just created a new project just to test this issue--here's the complete app delegate:

Applescript:


script AppDelegate
property parent : class "NSObject"
property theDate: missing value --variable taken from main_menu.xib but also needs to show current date initially
property search_month: "" --used for testing to show the integer value of the month selected of theDate

-- IBOutlets
property theWindow : missing value

on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
set theDate to (current date)

end applicationWillFinishLaunching_

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

on showtheDate_(sender) --shows the integer value of the month selected in the main_menu.xib when the button is clicked
set search_month to month of (theDate as date) as integer
display alert search_month
end showtheDate_

end script

in the main_menu.xib there is only an NSdate picker bound to theDate and an NSbutton that calls showtheDate_ which should show the integer value of the month of (current date)

When I run the application, there is no preselected date in the selector object--just the date defined in the atrributes selector of the NSdatepicker.

It is noteworthy that the VALUE is passed correctly. If you run the app and don't change the datepicker, the actual current month is returned. It is just not shown in the NSdatepicker object. The only way I can get the value to show in the NSdatepicker is to define it in the property declaration--which I've been told is written at compile time instead of script run time.

Last edited by cudaboy_71 (2017-12-04 09:59:47 am)

Offline

 

#6 2017-12-04 05:33:12 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: issue with 'current date' in archived application

cudaboy_71 wrote:

here's the complete app delegate:



That's not setting the value anywhere. As I said, set its value in applicationWillFinishLaunching:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2017-12-04 06:26:18 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: issue with 'current date' in archived application

so, am I to understand that I am not "setting" the value here by "setting the value" here? English is my first language. But, this is frustrating.

Applescript:


on applicationWillFinishLaunching_(aNotification)

set theDate to (current date)

end applicationWillFinishLaunching_

Offline

 

#8 2017-12-04 08:04:59 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: issue with 'current date' in archived application

Sorry, I see the issue now. Your code is creating a new local variable called theDate. Change it to:

Applescript:

set my theDate to (current date)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2017-12-05 07:33:52 am

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: issue with 'current date' in archived application

wow. that was simple.

I  thought there was an implicit bridging between ASOC and applescript variables. Without the 'my' pronoun, was I addressing two different variables? I have not been able to find any documentation on using 'my' when addressing variables in Xcode. This is not something I've ever seen in vanilla Applescript.

thanks.

Offline

 

#10 2017-12-05 08:06:01 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: issue with 'current date' in archived application

cudaboy_71 wrote:

This is not something I've ever seen in vanilla AppleScript.



The same thing can happen in vanilla AS. It's safest to always use "my" when setting a property within a handler.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)