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


Click here to return to the 'Using PDF Services, revisited' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Using PDF Services, revisited
Authored by: Fofer on Dec 27, '04 01:18:46PM

Submitter of the hint here. Thanks, Applescript guru, for sharing this script... that's exactly what I was hoping for! Works like a charm.

Curious if there's a way for the suggested filename to default to the name of the window we're printing though (as opposed to the generic "Print job.pdf.")

That way we could choose to leave it be if it's accurate, or edit/overwrite it with a better title. Can AppleScript handle that?



[ Reply to This | # ]
Using PDF Services, revisited
Authored by: strikeman on Dec 27, '04 02:01:51PM
Here's a script which can prepare an attachment for Entourage, as well as fill in the name of the current window as the default name of the PDF file.
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 (path to frontmost application as string)
			repeat
				set front_window_name to name of front window
				--				display dialog "Enter a name for file:" default answer file_name
				display dialog "Enter a name for file:" default answer (front_window_name)
				set this_name to the text returned of the result
				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 target_file to 
				(document file this_name of the parent_folder) as alias
		end tell
		tell application "Microsoft Entourage"
			activate
			set new_message to 
				(make new outgoing message with properties 
					{subject:"Interesting file", content:"This may be of interest", attachment:{file:target_file}})
			open new_message
		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
		else
			tell application "Finder" to delete parent_folder
		end if
	end try
end open


[ Reply to This | # ]
Using PDF Services, revisited
Authored by: Fofer on Dec 27, '04 02:17:12PM
Ah thanks for this. Using your script I was able to parse the lines I needed to combine with balakera's script, and now I am prompted to (re)name the receipt before saving. And it defaults to the name of the current web window, as opposed to "Print Job.pdf"! Okay, here goes:
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 (path to frontmost application as string)
			set front_window_name to name of front window
			repeat
				display dialog "Enter a name for file:" default answer (front_window_name)
				set this_name to the text returned of the result
				if this_name is not "" then exit repeat
			end repeat
		end tell
		tell application "Finder"
			set the name of this_file to this_name
			(* You would need to create a directory where you want resulting PDF files saved*)
			(* and type in the full path of that directory replacing the sample on the next line *)
			move this_file to "Users:username:Documents:Receipts" replacing yes
		end tell
	end try
end open
--- Now is there any way for the default name to have a .PDF suffix? That would be ideal.

[ Reply to This | # ]
Using PDF Services, revisited
Authored by: balakera on Dec 27, '04 03:08:58PM
To answer your last question - yes, it is possible to have default name to have .PDF suffix.
Here is the script:

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 (path to frontmost application as string)
                        set front_window_name to name of front window
                        repeat
                                display dialog "Enter a name for file:" default answer (front_window_name & "." & "pdf")
                                set this_name to the text returned of the result
                                if this_name is not "" then exit repeat
                        end repeat
                end tell
                tell application "Finder"
                        set the name of this_file to this_name
                        (* You would need to create a directory where you want resulting PDF files saved*)
                        (* and type in the full path of that directory replacing the sample on the next line *)
                        move this_file to "Users:username:Documents:Receipts" replacing yes
                end tell
        end try
end open


[ Reply to This | # ]
Using PDF Services, revisited
Authored by: Jason P on Dec 29, '04 01:04:02PM

I'm total new to scripting and am copying and pasting and referencing a few docs here and there to get what I want to happen, so please take baby steps with me in any reply.

My question is how do I take the script for saving a PDF to a folder, like "Receipts", and get it to NOT overwrite another PDF of the same name? Lets say I buy a lot of things from a site whose receipt page has a front window named "item receipt", and I simply want an elegant automatic way of the file getting appended with some sort iterative suffix prior to the .pdf if there already exists a file of the exact same name? I suppose it doesn't have to be appended prior to the .pdf, but that would be good. The Finder does this when saving Safari downloads. If you duplicate a download it simply appends a number.

Thanks for any help.
Jason



[ Reply to This | # ]
Using PDF Services, revisited
Authored by: balakera on Dec 27, '04 03:14:13PM
And for anyone who is using PowerMail here is the version that creates a new message with the PDF as an attachment:

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 (path to frontmost application as string)
			set front_window_name to name of front window
			repeat
				display dialog "Enter a name for file:" default answer (front_window_name & "." & "pdf")
				set this_name to the text returned of the result
				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 target_file to 
				(document file this_name of the parent_folder) as alias
		end tell
		tell application "PowerMail 5.1"
			activate
			set the new_message to 
				make new message with properties {content:" "}
			make new attachment at new_message with properties {file:target_file}
			open new_message
			
		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
		else
			tell application "Finder" to delete parent_folder
		end if
	end try
end open


[ Reply to This | # ]
Using PDF Services, revisited
Authored by: u2mr2os2 on Dec 27, '04 02:25:11PM

Safari, at least, names the file with the name of the page. Not tested other apps. OS X 10.3.7, Safari 1.2.4.



[ Reply to This | # ]
Using PDF Services, revisited
Authored by: u2mr2os2 on Dec 27, '04 02:48:02PM

To clarify, the PDF you get is named with the title of the document printed if you place an alias of a folder in your "/Library/PDF Services" or "~/Library/PDF Services" folders. Using the script given above, you get the generic "Print Job.PDF". I checked, and other apps seem to name the file with a title: Mail, TextEdit and AppleWorks. Script Editor did not.



[ Reply to This | # ]