open link in safari, email contents as pdf

Hi all,

I’m trying to do a few things here.

  1. Open a script at 6:59 PM
  2. Have script open a website
  3. Have script email contents of the website as a PDF using Mail

Here’s what I have so far.

set a to getTimeInHoursAndMinutes()

if a > "6:59 PM" and a < "7:00 PM" then
	
	tell application "Safari"
		activate
		open
		tell window 1
			set current tab to (make tab with properties {URL:"http://ppsnet/management/BurbankSchedule.pdf"})
			--		set current tab to (make new tab with properties {URL:"http://ppsnet/management/BurbankSchedule.pdf"})
			--		tell window 1 to set properties to {URL:"http://ppsnet/management/BurbankSchedule.pdf"})
		end tell
	end tell
	
else
	return false
end if

on getTimeInHoursAndMinutes()
	-- Get the "hour"
	set timeStr to time string of (current date)
	set Pos to offset of ":" in timeStr
	set theHour to characters 1 thru (Pos - 1) of timeStr as string
	set timeStr to characters (Pos + 1) through end of timeStr as string
	
	-- Get the "minute"
	set Pos to offset of ":" in timeStr
	set theMin to characters 1 thru (Pos - 1) of timeStr as string
	set timeStr to characters (Pos + 1) through end of timeStr as string
	
	--Get "AM or PM"
	set Pos to offset of " " in timeStr
	set theSfx to characters (Pos + 1) through end of timeStr as string
	
	return (theHour & ":" & theMin & " " & theSfx) as string
end getTimeInHoursAndMinutes

Basically, I can only access internal links while I’m at work. I want to find out my schedule by 7pm the previous night. I want it to go to the schedule and email it to me. Any advice would be greatly appreciated.

Hi,

if the source is a PDF file, Safari is not needed.
Try this


property sixFiftyNinePM : (18 * hours) + (59 * minutes) -- seconds of 6:59 PM since midnight
property sevenPM : 19 * hours -- seconds of 7:00 PM since midnight

property myaccount : "John Doe <john@doe.com>"
property theSubject : "mySubject"
property recipName : "Henry Smith"
property recipAddress : "henry@smith.com"

set scheduleFile to (path to temporary items as text) & "BurbankSchedule.pdf"
set currentTime to time of (current date)
if currentTime > sixFiftyNinePM and currentTime < sevenPM then
	try
		-- download the PDF file to temporary items folder
		do shell script "curl -o " & quoted form of POSIX path of scheduleFile & space & "http://ppsnet/management/BurbankSchedule.pdf"
		-- if credentials are required use
		-- do shell script "curl -o " & quoted form of POSIX path of scheduleFile & " -u username:password " & "http://ppsnet/management/BurbankSchedule.pdf"
		tell application "Mail"
			set newMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:return & return}
			tell newMessage
				set sender to myaccount
				make new to recipient at end of to recipients with properties {name:recipName, address:recipAddress}
				tell content to make new attachment with properties {file name:scheduleFile as alias} at after the last paragraph
			end tell
			send newMessage
			
		end tell
		-- delete temporary file
		do shell script "rm " & quoted form of POSIX path of scheduleFile
	on error e
		display dialog "An error occurred: " & e buttons {"Cancel", "OK"} default button "OK"
	end try
end if