I’m trying to write a script – or Automator action that calls a script – that I can save into ~Library/PDF Services/ and run from the Print dialogue box in pretty much any application (by selecting it from the PDF dropdown in that dialogue).
The script should:
Prompt me for a filename, inserting as the default the text that I have selected in the file (or, alternatively, text that I have copied from the file and which is already in the clipboard).
Save the file, with the filename, to a specific, pre-determined folder (the same folder every time), without asking me about it.
If possible, I’d like the script to then take the PDF file I just created and saved and attach it to a new email message in my default email application (which is Postbox). This part of the script, I think I can figure out, by using variables from above instead of 'aAttachmentPath" in the script below:
tell application "Postbox"
send message subject "Invoice" body "Attached please find a new invoice from me." attachment aAttachmentPath with args
activate
end tell
(If you wonder what I’m doing - I’m creating an invoice, saving as a PDF with the invoice number to the invoices folder on my computer, and then emailing the invoice to a client)
taken from that thread I adapted some code to take the contents of the clipboard and use that as the title
you will need to export your script as an application, and put it in the pdf services folder.
on open these_items
try
set this_file to item 1 of these_items
tell application "Finder"
set ClipBoardContents to the clipboard
--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
--display dialog "Enter a name for file:" default answer file_name
display dialog "Enter a name for file:" default answer ClipBoardContents
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
move this_file to "Macintosh HD:Users:Budgie:Desktop:FINAL:" replacing yes
end tell
end try
end open