roccitman Posted November 23, 2016 Posted November 23, 2016 Hey Gang Working on this workflow. I want to be able to put one date in, then another date, and have the result be the number of days between the two (Just days, not months, weeks, and days). This (possibly klunky) AppleScript seems to generate the expected result, but I don't know how to get the result spat back out to Alfred so I can post it or whatever. I'm sure it's something simple, any help appreciated! set firstDate to "20171231" set resultDate1 to the current date set the year of resultDate1 to (text 1 thru 4 of firstDate) set the month of resultDate1 to (text 5 thru 6 of firstDate) set the day of resultDate1 to (text 7 thru 8 of firstDate) set the time of resultDate1 to 0 set secondDate to "20171201" set resultDate2 to the current date set the year of resultDate2 to (text 1 thru 4 of secondDate) set the month of resultDate2 to (text 5 thru 6 of secondDate) set the day of resultDate2 to (text 7 thru 8 of secondDate) set the time of resultDate2 to 0 set answer to ((((resultDate1 - resultDate2) / 60) / 60) / 24) return answer NOTE: I'm using dates this way for my own preference, I get tons of these dates and need to quickly get the difference in number of days.
vitor Posted November 23, 2016 Posted November 23, 2016 5 hours ago, roccitman said: how to get the result spat back out to Alfred so I can post it or whatever. That’s very unclear. You need to be more specific about what you want to do with the result. As it is, if you connect that code in a node to another node in Alfred, it’ll just pass the result.
roccitman Posted November 23, 2016 Author Posted November 23, 2016 Ah yes sorry. I would like for the result of the script to be able to be posted to large type. Doesn't seem to work for me though.
vitor Posted November 23, 2016 Posted November 23, 2016 Works perfectly fine for me. Please post a link to your workflow so I can see what might be the problem.
roccitman Posted November 23, 2016 Author Posted November 23, 2016 Thanks for your help! Here's what I have so far: http://d.pr/f/n0v2
roccitman Posted November 23, 2016 Author Posted November 23, 2016 Another note, you'll see in the workflow, I am trying to pass variables into the script and I think that's partly to blame. In the script sample above it's just hard coded dates.
vitor Posted November 23, 2016 Posted November 23, 2016 Here is the fixed workflow. Changes, in no particular order: 1date and 2date changed to date1 and date2. Don’t start variable names with numbers. Seldom (if ever) a good idea (for more context, Stack Overflow answer, Quora answer). Changed NSAppleScript node to Run Script node. Last Args and Vars node was deleted. Its contents made no sense and it was unnecessary, anyway. Large Type needs only {query} (i.e. output of last command). The way you were calling variables was incorrect. Open the debugger and see the errors. For the correct way, see this post. Changed set for return. Changed as real to as integer. Seems more like what you would want as a result.
roccitman Posted November 23, 2016 Author Posted November 23, 2016 Oh wow, ok learning a lot. Thank you thank you! And have a great Turkey Day
vitor Posted November 23, 2016 Posted November 23, 2016 16 minutes ago, roccitman said: Oh wow, ok learning a lot. Thank you thank you! Glad to help. 16 minutes ago, roccitman said: And have a great Turkey Day Thank you, but I’m Portuguese, these dates have no special meaning to us. A happy thanksgiving to you!
roccitman Posted November 23, 2016 Author Posted November 23, 2016 Too soon for Restoration of Independence day And a good night to you, thanks again!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now