Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Yet another customized script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Yet another customized script
Authored by: vgz on Dec 27, '04 03:59:38PM
Here's my modification of the example script.

This script prompts you for a name for the file (defaulting to the domain of the page you are viewing) and appends the current date and time to the filename while saving it to a specified directory.

Note: Change "Path:to:the:folder:" to the actual path to the folder you want to save in.

on open these_items
	try
		set this_file to item 1 of these_items
		tell application "Finder"
			set the file_name to the name of this_file
			set the parent_folder to (the container of this_file) as alias
		end tell
		tell application "Safari"
			set current_url to the URL of document 1
			set default_name to ""
			set current_num to 8
			repeat
				set current_character to character current_num of current_url
				if current_character is not "/" then
					set default_name to default_name & current_character
				else
					exit repeat
				end if
				set current_num to current_num + 1
			end repeat
		end tell
		tell application (path to frontmost application as string)
			repeat
				set the_date to current date
				set current_time to time string of the_date
				set safe_time to ""
				set current_num to 1
				repeat
					set current_character to character current_num of current_time
					if current_character is ":" then
						set safe_time to safe_time & "."
					else
						set safe_time to safe_time & current_character
					end if
					set current_num to current_num + 1
					if current_num > length of current_time then exit repeat
				end repeat
				set name_extension to " " & month of the_date & " " & day of the_date & ", " & year of the_date & " " & safe_time & ".pdf"
				display dialog "Enter a name for file:
(Note: '" & name_extension & "' will be appended to the end of the name.)" default answer default_name
				set this_name to the text returned of the result
				set this_name to this_name & name_extension
				if this_name is not "" then exit repeat
			end repeat
		end tell
		tell application "Finder"
			set the name of this_file to this_name
			set the_destination to "Path:to:the:folder:" as alias
			set the target_file to 
				(document file this_name of the parent_folder) as alias
			move target_file to the_destination replacing yes
		end tell
	on error error_message number error_number
		if the error_number is not -128 then
			tell application (path to frontmost application as string)
				display dialog error_message buttons {"OK"} default button 1
			end tell
		end if
	end try
end open

---
VGZ:
Otaku, Fanfic author, and Mac Fanatic

[ Reply to This | # ]

Good script, but
Authored by: Jason P on Dec 29, '04 02:15:18PM

I'm trying to get a script that works elegantly for various applications files like excel, textedit, ...script editor, whatever, in addition to Safari. Your script as written, pulls the domain name of the active web page as the default name, but it doesn't pull the name of an active document or application window as a default name to save as. I have been fiddling with it quite a bit to get it to work, but can't seem to do it. It only likes to pull the domain name out of Safari. Would you be so kind as to give me some hints as to what to change to pull a document or application window name as the default name when trying to print to .pdf in those cases as well?

Thank you.



[ Reply to This | # ]