Is it possible to have an AppleScript that, when activated, will present me with a date picker to select a “start date” and then once the start date is selected, the script will past a text string into the open application in the format of (start date – start date+4days).
So if I selected 12/14/2015 as a start date, the script would return the following text string:
12/14/2015 – 12/18/2015
Thanks
Hi. If you mean a standard addition style chooser, such as file/folder/color, etc., there is none. It’s possible to arrive at a date, using a dialog.
set {setoff, isdate} to {4, (display dialog "Edit to desired date." default answer (current date)'s date string)'s text returned} --The day of the week can be ignored
tell date isdate to set startDate to ((its month as integer) & "/" & day & "/" & year) as text
tell ((date startDate) + setoff * days) to set endDate to (get {its month as integer, "/", day, "/", year})
{startDate, " - ", endDate} as text
I use Pashua to do such a thing.
Thanks Guys!
Marc,
Your script works great if I use it in a Word or Excel document. I launch the script using a TextExpander snippet. But its not working inside of a browser window. The script will run and I get the initial dialog box with the date picker, but the script doesn’t complete and paste in the final text after I pick the date. In fact, I can’t get it to work properly in any other application. Any thoughts?
I can’t advise you with TextExpander, since I’m not familiar with it. How did you change the code for your use? As written, the script simply returns the value to the editor.
If you want to copy it:
set the clipboard to {startDate, " - ", endDate} as text
I didn’t change your script at all. All TextExpander is doing is launching the script when I type a “snippet.” When I type “cw” for “current week”, it launches the script. The dialog window opens and allows me to select my start date.
When I open Word or Excel and type “cw” the script behaves like its supposed to. But if if I type “cw” in this message reply box, the date picker launches and allows me to pick the start date but then nothing else happens.
I don’t think TextExpander is the problem. I’m not sure how I would test it without using TextExpander to launch the script. Running the script within Applescript obviously puts the results in the bottom of the AS window and not in a field in a browser window I may have open.
I think I see the problem. You said, “as written, the script returns the value to the editor.” I want the value to be returned to the field I am in within an application for safari window, not the editor. Is that possible? When I run the script from within Word or Excel, the result is returned to the document and not the editor.
Jay
I’ve made a short screen recording that shows how I am executing this applescript using textexpander in both a Word document and on this website. http://cl.ly/0q2A2h1T1x1C
The script does exactly what I am wanting, its just not working where I want it to work. I actually don’t need this in an Office document. I need it for a particular web application. I just happened to notice that it would work in Word and Excel but can get the script to work in any other application. Is there another way to launch an applescript and have it return its value within the app and not the editor?
Thanks
http://cl.ly/253g3S030z11
I believe I have it working. All that was required was that I click the mouse where I wanted the value to be returned instead of just hitting Enter. This short video shows it working exactly where and how I was wanting this to work. I make out a service invoice every week and it will be for the services provided Monday through Friday. The reason I wanted the script was that it takes extra time to manually type out the dates like this when working from my laptop that doesn’t have a number pad. So this works MUCH quicker.
Thank you very much for helping me out!
Jay