You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do I put in date range in a website to pull documents In apple scripts

Hi

so I am completely new to Apple Scripts, so I pull daily documents from websites and some websites ask for a date range for eg 03-01-2022 to 03-08-2022 so how do I put this number in that box and how do I make it change everyday for example the next day I have to put in 03-02-2022 to 03-09-2022


Thank for the help in advance

Posted on Mar 10, 2022 11:36 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 11, 2022 1:15 PM

Incorporate this into your existing code:


use scripting additions

property now_date : space
property week_ago : space

set now_date to (do shell script "date -j -u +%m-%d-%Y")
set week_ago to (do shell script "date -j -u -v-1w +%m-%d-%Y")


tell application "Google Chrome" to activate
tell application "System Events"
	tell process "Google Chrome"
		
		keystroke now_date
		keystroke week_ago
		key code 36
		
	end tell
end tell


10 replies
Question marked as Top-ranking reply

Mar 11, 2022 1:15 PM in response to Ash8420

Incorporate this into your existing code:


use scripting additions

property now_date : space
property week_ago : space

set now_date to (do shell script "date -j -u +%m-%d-%Y")
set week_ago to (do shell script "date -j -u -v-1w +%m-%d-%Y")


tell application "Google Chrome" to activate
tell application "System Events"
	tell process "Google Chrome"
		
		keystroke now_date
		keystroke week_ago
		key code 36
		
	end tell
end tell


Mar 10, 2022 2:53 PM in response to Ash8420

There are many ways to go about this.


More than anything you need to understand the specifics of the site and the URLs in question.


Fox example, if the site requires the start and end dates to be entered into a field on a web form, then you're almost certainly going to need to use JavaScript to interact with the page (JavaScript is the de facto way to manage web content within a browser).

On the other hand, if the URLs are consistent and predictable (e.g. https://www.site.com/report?start=03-01-2022&end=08-08-22 ) then it may be no more complex that compiling a URL string with the appropriate fields and filling in the blanks.


There's also a lot of variance in the dates - your post implies that somehow the script should 'know' that the last time it was used, the dates 3/1/22 through 3/8/22 were used, and therefore the next run would be 3/2/22 through 3/9/22. That's different from prompting the user for start and end dates.

In addition, are the dates always a week apart? Can the user enter one (e.g. start date) and the script automatically calculate the end? or maybe the report is always for 1 week prior to today? Lots of way to slice this.


In short, more detail is needed before a path forward can be determined.

Mar 11, 2022 5:11 AM in response to Camelot

hi Camelot thanks for replying

So I have no idea how java scripts work and yes the URLs are pretty consistent

Is there any way to put the end date first which will be the current date and then the script will calculate (-7 days) and input in the blank field?

Yes the dates are always a week apart


also, can the script make a report on excel of the documents it pulled

(I know I am asking a lot but just need some help as this will reduce 60% of my job)

I logged it the site bye using basic apple scripts function


tell application "Google Chrome" to activate

tell application "System Events"
	key code 17 using command down
	delay 1
	key code 37 using command down
	delay 2

keystroke "url"

	key code 36
	delay 2
	key code 3 using command down
	delay 1
	keystroke "User Name:"
	key code 36
	delay 1
	key code 53
	delay 1
	key code 48
	delay 1
	keystroke "username"
	delay 0.5
	key code 48
	keystroke "password"
	repeat 7 times
		key code 48
	end repeat
	key code 36
	delay 2
	repeat 4 times
		key code 48
	end repeat
	key code 36
	delay 7
	key code 3 using command down
	keystroke "Search within the site"
	key code 36
	delay 1
	key code 53
	delay 1
	key code 36
	delay 2
	key code 3 using command down
	keystroke "search withing the site"
	key code 36
	delay 1
	key code 53
	delay 1
	key code 36
	delay 2
	repeat 7 times
		key code 48
	end repeat
	key code 36
	delay 1
	repeat 9 times
		key code 48
	end repeat
	delay 1
	repeat 3 times
		key code 125
	end repeat
	key code 36
	delay 3
	key code 48
-- this is how i have to manually put a week range date
	keystroke "03"
	keystroke "01"
	keystroke "2022"
	keystroke "03"
	keystroke "09"
	keystroke "2022"
	key code 36
	
	
end tell

also i have to login to atleast 30 sites like these everyday




Thank you so much

Mar 11, 2022 7:00 AM in response to Ash8420

You will still need to use JavaScript to get at those form date fields at the site displayed in the browser. Key codes and Keystrokes are not going to achieve this.


use scripting additions

set now_date to (do shell script "date -j -u +%m-%d-%Y")
"03-11-2022"
set week_ago to (do shell script "date -j -u -v-1w +%m-%d-%Y")
"03-04-2022"



How do I put in date range in a website to pull documents In apple scripts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.