Download Monitor

Im trying to use applescript monitor my downloads so that when a download is complete, it will trigger a script.

Have seen a program on windows called Keytext3 that will monitor the color of a pixel on the screen.
That way it can monitor for color changes on the download manager to see if a download is complete.

One of the apple utilities can do monitor color - the digital color meter but unfortunately it is not scriptable?

Then I tried using Prefab UI browser to get the window name of my firefox download manager.
Because firefox download manager window updates the percentage of download, I thought I would check that value using applescript at fixed intervals and monitor my download. But for unknown reasons ( unknown to me ) It does not work. And safari download manager window does not have an attribute that can be used in applescript.

Could any one suggest a work around?

Also which browser is one that is the most applescript compatible?

There are scripts about that monitor the download folder. (folder actions )

When safari downloads a file it adds a extension to the end o f the file .download when the file is complete it removes the .download extension. The scripts look for new file added and then run the rest of the script when the name of the file does not end with .download

Thanx :slight_smile:

Here’s what I use. It watches your downloads folder by checking its size. When the size of the downloads 0folder stops changing it knows your downloads are finished, at which time the script can then do whatever you want.

-- this watches a folder by checking its size. When the size stops changing the script knows the downloads are finished. The time delay is the delay the script waits between checks of the size.

set theItem to (choose folder)
set time_delay to 5

set success to my watchChangingFolderSize(theItem, time_delay)

if success then
	display alert "Success:" message "The items have been download." as informational
	display alert "Error:" message "The script stopped for some reason." as warning
end if

on watchChangingFolderSize(theItem, time_delay) -- loop until the size of (theItem) stops changing over time
	set theItem to theItem as string
	set sizeThen to size of (info for file theItem) --get initial size
	repeat --if they don't equal then loop until they do
			delay time_delay
			set sizeNow to size of (info for file theItem) -- get new size
			if sizeNow - sizeThen = 0 then exit repeat
			set sizeThen to sizeNow
		on error
			return false
			exit repeat
		end try
	end repeat
	return true
end watchChangingFolderSize

Wow !! Thank you so much for that solution.

I am hoping to use this script for downloading Parchive files created using split and concat. Unfortunately download managers do not recognize files with extensions .001, .002 and so on.

One question about the code though -

why use

size of (info for file theItem)


size of file (theItem)

The dictionary does not speak of the keyword “info” for file ? Or may be I havent been there yet?

Is there any advantage of using launchd to run this script like every 10 or 15 seconds especially if the file being downloaded takes a while to download?

The advantage of using “info for file” is that you don’t have to tell any application to do this command. This command is just understood by applescript. Using the “size” command I think that’s part of the Finders dictionary, so you would have to tell application “Finder” to get the size. If you look at the “info for” command by using a script like this you can see all of the properties you can get from a file without “telling an application” to get the properties. Does that make sense?

set a to choose file
set b to info for a

As far as using launchd to run the script, it wouldn’t work because you’re not always downloading a file. The script only continues running when you’re downloading a file, once the folder you’re watching stops changing size then the script stops running.

I guess you could tell launchd to watch a folder for changes, and then when a file is added to that folder (ie. a change is made to that folder because you started downloading a file which was added to that folder) to run this script. I think launchd can work that way but I haven’t done this so I can’t help with that.

Basically the way I use the script is I hard-coded the path to my downloads folder in the script. So instead of the line that says…
set theItem to (choose foder)
I use…
set theItem to path:to:downloads:folder

That way when I start a download I can just run the script and I’m certain that it’s watching the right folder without me picking it from the dialog box.

Thanks you so much regulus…


additional to regulus’ extensive explanation I’d like to say, info for [alias] is a part of the Standard Scripting Additions.
The result is a record of a bunch of informations about a file or folder without involving the Finder or System Events

For example Picture1.png (a simple screenshot) on my desktop

info for alias (((path to desktop) as Unicode text) & "Picture1.png")


creation date:date "Sonntag, 27. Mai 2007 18:00:48 Uhr", 
modification date:date "Sonntag, 27. Mai 2007 18:00:49 Uhr", 
icon position:{0, 0}, 
package folder:false, 
extension hidden:true, 
name extension:"png", 
displayed name:"Picture1", 
default application:alias "Macintosh", 
kind:"Portable Network Graphics Image", 
file type:""
file creator:""
type identifier:"public.png", 
busy status:false, 
short version:"", 
long version:""}

Thank you. that was good info 'bout info :slight_smile:

You could use AppleScript to download, since it waits for the download to complete before moving on, its simple logic.

Here a simple example

set TheURL to ""
set TheName to "itunesplus20070530.jpg"
set thepath to (path to desktop) as string

tell application "URL Access Scripting"
	download TheURL to file (thepath & TheName) replacing yes
end tell

tell application "Finder"
	display dialog "Finished, Now what?"
end tell

Hope that helps