Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rating: Thread Rating: 9 votes, 5.00 average. Display Modes
Old 11-25-2011, 07:28 AM   #1
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
Creating a PDF workflow that saves a PDF file.

I have recently discovered that Apple no longer supplies a "Save As PDF-X" workflow with Lion, and that copying the workflow from 10.6 to Lion doesn't work.

So, I want to produce a PDF workflow ("print plug-in") that applies the OS Quartz Filter "Create Generic PDFX-3 Document" and then prompts the user for a save location and saves the file.

Now in Automator, it is easy enough to apply the filter, with the automator "Apple Quartz Filter" action, but it seems harder to bring up a file dialog and save the PDF. No such action exists.

So I need an AppleScript that prompts for a filename and the saves the PDF.

I've tried using:
Code:
set myFile to choose file name with prompt "Save file as:"
save input in myFile
but that doesn't seem to work. Probably a basic error, but then isn't it always?

Any help gratefully received.
benwiggy is offline   Reply With Quote
Old 11-29-2011, 02:47 AM   #2
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
As ever, it's a bit more complicated than that. Here's a suitable script I found in another print plug-in here:

Code:
on run {input, parameters}
	
	-- parse output folder and file names
	
	set outfile to (choose file name default name "untitled" default location path to desktop) as string
	set len to length of outfile
	
	tell application "Finder"
		
		repeat with i from 0 to len
			if text (len - i) of outfile is ":" then
				exit repeat
			end if
		end repeat
		set i to len - i
		set outfp to text 1 thru (i - 1) of outfile
		set outfn to text (i + 1) thru len of outfile
		if outfn does not end with ".pdf" then
			set outfn to outfn & ".pdf"
		end if
		
		-- parse input folder and file names
		
		set parm to (item 1 of input) as string
		set len to length of parm
		repeat with i from 0 to len
			if text (len - i) of parm is ":" then
				exit repeat
			end if
		end repeat
		set i to len - i
		set infp to text 1 thru (i - 1) of parm
		set infn to text (i + 1) thru len of parm
		
		-- rename the file and move it to the output folder
		
		set name of file parm to outfn
		set tmp to infp & ":" & outfn
		move file tmp to folder outfp with replacing
		
	end tell
	return true
	
end run
I suspect someone here will be able to make this even more efficient.
benwiggy is offline   Reply With Quote
Old 11-29-2011, 05:31 AM   #3
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
No, that doesn't work on Lion either.
First I get an error saying "Couldn't Create a PDF/X-3 document", then I get the save dialog, and then "The action encountered an error".

However, I have had success with an action just to move the file to the Desktop.
benwiggy is offline   Reply With Quote
Old 12-03-2011, 03:34 AM   #4
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
I've tried this, too:
Code:
tell save panel
    set title to "Save file"
    set prompt to "Save"
    set required file type to "pdf"
    set treat packages as directories to false
end tell
set theResult to display save panel with file name "Untitled"
But I get an error that indicates that the syntax after "Required" and "Treat" is unexpected, as if it can't handle multi-word concepts.

Anyone.....?

There are usually some real AppleScript geniuses here, and surely saving a file in an Automator workflow must be easier than this...!!!
benwiggy is offline   Reply With Quote
Old 12-03-2011, 10:03 AM   #5
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,649
This isn't scripting guidance, and I'm not even certain if this will help you, but I'll share it and let you decide. You can easily make a Create Generic PDFX-3 Document Quartz filter so that it appears in a Print dialog under the PDF button.
  1. Open Colorsync Utility.
  2. Find the Create Generic PDFX-3 Document filter that Apple supplies, then click on the downward-pointing triangle to the far right and select Duplicate Filter.
  3. Go to the copy that was just made, change its name if you want by double clicking it, then click the disclosure triangle to the left of the filter name.
  4. Click the disclosure triangle to the left of Create PDF/X-3 Document to configure it as desired. It's identical to the Apple-supplied one except it doesn't have a Destination Profile assigned.
  5. Click the disclosure triangle to the left of Domains and check the box for PDF Workflows and, if desired, Printing.
Once that is done, the item will appear in the Print dialog under the PDF button. Testing on my system, it seemed to work fine, but I was never prompted for a save location and the PDF was simply placed on the Desktop.

But the PDF Service/Quartz Filter you created with ColorSync is available to Automator. Open a new window in Automator and choose Print Plugin. When building your plugin, at some point you'll want to use the Apply Quartz Filter To PDF Documents action. That includes a pop-up menu from which you can choose the Quartz Filter you created.
NaOH is offline   Reply With Quote
Old 12-03-2011, 10:37 AM   #6
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
Are you using Lion? Because I've already reported that user-created Quartz Filters don't always work in Lion -- even if they are duplicates of the system ones.

However, you may have hit something, as the default system filters do not have their "Domains" set to include printing or Print plug-ins. (How stupid is that?)

Anyway, I've tried your suggestion and I still get a "Could not create PDF-X document" error message, and no PDF in the Desktop. On 2 Macs.
benwiggy is offline   Reply With Quote
Old 12-03-2011, 10:41 AM   #7
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,649
Yes, I'm running Lion, and now that you mention it I do recall your other thread regarding issues with this Quartz filter.

What setup did you use with your duplicate Quartz filter? Was that through an Automator Workflow and/or Print Plugin? When I created the duplicate Quartz filter, it automatically appeared in the Print dialog under the PDF button, and using that placed the PDF on the Desktop.
NaOH is offline   Reply With Quote
Old 12-03-2011, 10:52 AM   #8
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
Ahhhhh!!

Ticking the "Pdf Workflows" domain in ColorSync Utility MOVES the user filter from ~/Library/Filters to ~/Library/PDF Services!!!!

And then, if you select the Filter in the PDF menu (and not the Print Workflow/plug-in created in Automator), you get a PDF file on the Desktop.

However, according to Acrobat, it's not PDF-X3 compliant so the filter hasn't actually been applied.

Arrgh.

EDIT: I've tried editing the xml of the System Quartz Filter to allow PDF workflow and Printing. It still produces the "can't produce PDF X document" error.
I suspect it's some sandboxing thing preventing the saving of the file.

Last edited by benwiggy; 12-03-2011 at 10:57 AM.
benwiggy is offline   Reply With Quote
Old 12-03-2011, 11:16 AM   #9
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,649
Two tips from the end of this post (technically about 10.6 but I figure worth a try on your end under 10.7): 1) set your Quartz filter to use 300 DPI and 2) avoid the flattened transparency option.
NaOH is offline   Reply With Quote
Old 12-03-2011, 11:28 AM   #10
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
I've cracked it.

When ColorSync Utility dupes the filter, it's only 1K, whereas the filter in /System/Library/Filters in 79K.

Copying it in the Finder to ~/Library/PDF Services (and adding the XML:
Code:
<key>PDF Workflow</key>
		<true/>
		<key>Printing</key>
to the Domains key

means you can use the PDF-X3 filter in the PDF button of the print menu, and a PDF-X3 document is saved to the Desktop.

However, there still seems to be no way of including filters within print workflows in Automator, nor of setting the location for where to save the file.

Interesting about the dpi thing in that thread. Most of what I do is vector, but still more grist to the PDF mill.
benwiggy is offline   Reply With Quote
Old 05-18-2012, 10:03 PM   #11
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,649
In case it's of any use, I saw an article on an Automator-based Service for shrinking PDFs and it reminded me of this thread.

http://www.leancrew.com/all-this/201...omator-service
NaOH is offline   Reply With Quote
Old 05-19-2012, 05:43 AM   #12
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
Thanks. I've posted there about the bugs I've found in Lion relating to Quartz Filters and Preview.
I reported the bugs to Apple in November. If Mountain Lion is coming out soon, then I don't know what that means for Lion development and support.
benwiggy is offline   Reply With Quote
Old 05-19-2012, 11:51 AM   #13
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,649
Quote:
Originally Posted by benwiggy
If Mountain Lion is coming out soon, then I don't know what that means for Lion development and support.

This gets at an implication I have with the yearly OS release schedule Apple has announced. If Apple holds to its previous actions, this means the prior OS will get some security updates but fewer bug fixes will be issued since the OS will be current for less time. I realize that moving to the next OS will only cost US $30, but I never install a point-zero release. From that angle, it sounds like the best I'll get is about 11 months of an OS being completely supported.

It's certainly possible that I've oversimplified how this will play out. Or that there's something I've missed (or don't yet know). But it's looking like bug fixes will largely be coming from major OS releases. Can't say I like the looks of that.
NaOH is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:17 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.