• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
new AutoAPOD broke
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new AutoAPOD broke


  • Subject: new AutoAPOD broke
  • From: Robert Poland <email@hidden>
  • Date: Tue, 10 Jan 2017 16:05:41 -0700
  • Z-usanet-msgid: XID713VaJXFQ1056X33

Excuse the long message, but I don't know where to truncate it.

I have been using the script (below) for almost 7 years and now it fails, since about the first of the year.

Reports that "http://apod.nasa.gov/apod/"; is unavailable, but I can access it directly from Safari.

I would appreciate help.

(* new AutoAPOD - 10/1/04 - from Johnny AppleScript <email@hidden> *)

on run
	main()
end run

on main()
	try -- exit gracefully if script won't run
		set test to false -- false disables dialogs
		set {y, m, d} to {year, month, day} of (current date)
		set flag to quoted form of (y & " " & m & " " & d as string) --> "2004 September 26"
		set yn to y as text --> "2004"
		set yn to characters -2 thru -1 in yn as string --> "04"
		set mn to (m as number) as text --> "9"
		if number of characters in mn < 2 then set mn to "0" & mn -->  "09"
		set dn to d as text --> ex.:  "6"
		if number of characters in dn < 2 then set dn to "0" & dn --> ex.:   "06"
		set pFlag to yn & mn --> "0409"
		set dateTAG to pFlag & dn --> "040926"
		set rootURL to "http://apod.nasa.gov/apod/";
		set archiveEXT to "archivepix.html"
		-- http://apod.nasa.gov/apod/archivepix.html - 2004 September 26
		try
			set APOD to do shell script "curl " & rootURL & archiveEXT & " | grep " & flag
		on error
			-- if test then
			display dialog "1, APOD Image Retriever: " & return & rootURL & return & "is currently unavailable. Please try again later." buttons {"Poopy"} default button 1 giving up after 5 with icon 2
			return
		end try
		set leadTAG to "<a href=\""
		set trailingTAG to "\">"
		set leadTAG1 to (offset of leadTAG in APOD)
		set trailingTAG1 to (offset of trailingTAG in APOD)
		set apodEXT to characters (leadTAG1 + 9) thru (trailingTAG1 - 1) in APOD as string
		-- set apodName to characters (trailingTAG1 + 2) thru -9 in APOD as string
		try
			set curAPOD to do shell script "curl " & rootURL & apodEXT & " | grep href | grep jpg  | grep " & pFlag -- Doh! What if it's a GIF?
		on error errMsg
			try
				set curAPOD to do shell script "curl " & rootURL & apodEXT & " | grep href | grep gif | grep " & pFlag
				-- this method is bound to fail. We need a better analysis; can you think of one?
			on error
				if test then display dialog "2, APOD Image Retriever: locate daily image failed: " & errMsg with icon 0 -- giving up after 15

			end try
		end try
		set leadTAG2 to (offset of leadTAG in curAPOD) -- using a different flag length than above
		set trailingTAG2 to (offset of trailingTAG in curAPOD) -- using a different flag length than above
		set imageEXT to characters (leadTAG2 + 9) thru (trailingTAG2 - 1) in curAPOD as string
		set filename to reverse of every character of imageEXT as string
		set filename to reverse of every character of (characters 1 thru ((offset of "/" in filename) - 1) in filename as string) as string
		set filename to dateTAG & "-" & filename -- let's add today's date string to the prefix for our own archives
		set imageURL to rootURL & imageEXT
		set folderName to "APOD ƒ"
		set destinationFolder to ((path to pictures folder) & folderName & ":" as string) -- we'll need to use this path more than once, so let's give it a unique variable name
		tell application "Finder" to set dfExists to (exists folder destinationFolder)
		if dfExists is false then tell application "Finder" to make new folder at (path to pictures folder) with properties {name:folderName}
		set filePath to POSIX path of destinationFolder -- here's the first use; we need a UNIX-style path string; i.e.,  /Users/bob/Pictures/
		set ThePicture to ((destinationFolder & filename) as string) -- here's the second use; we need and HFS-style path string; i.e., :Users:bob:Pictures:file_name
		tell application "Finder" to set downloadOption to (exists file ThePicture)
		if downloadOption is false then
			set getImage to "curl " & imageURL & " -o " & "\"" & filePath & filename & "\""
			try
				do shell script getImage
			on error errMsg
				if test then display dialog "3, APOD Image Retriever: download failed: " & errMsg with icon 0 --  giving up after 15
			end try
			-- set desktopSet to button returned of (display dialog "Set image as desktop?" buttons {"No", "Yes"} default button 1 with icon 1 giving up after 10)
			try
				set ThePicture to ThePicture as alias -- need to make a file path string into an object Finder can recognize
				-- if desktopSet is "Yes" then
				tell application "Finder" to set desktop picture to ThePicture
			on error errMsg
				if test then display dialog "5, " & return & errMsg with icon 0 -- giving up after 15
			end try
			-- end if
		else
			ignoring application responses
				# say "autopod im age already downloaded"
			end ignoring
		end if
	on error errMsg
	end try
	return
end main

on delay delayTime
	try
		set theRepeat to delayTime * 10 div 1
		repeat theRepeat times
			do shell script "sleep 0.1"
		end repeat
	on error
		repeat 10 times # default time - 1 second
			do shell script "sleep 0.1"
		end repeat
	end try
end delay

TIA,

Robert Poland
Fort Collins, CO


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: new AutoAPOD broke
      • From: Christopher Stone <email@hidden>
  • Prev by Date: Re: Strange error -10810 when running applets
  • Next by Date: Re: new AutoAPOD broke
  • Previous by thread: Re: Satimage navchoose object issue
  • Next by thread: Re: new AutoAPOD broke
  • Index(es):
    • Date
    • Thread