scripting PDF import

57 views
Skip to first unread message

Jonathan

unread,
Feb 6, 2009, 12:20:20 PM2/6/09
to Yojimbo Talk
I was wondering if anyone has written an applescript (possibly tied to
a folder action) for directly importing pdf's that also deletes the
original pdf. To make myself a little clearer... It would be nice to
have folder on my desktop ("pdf to YJ") that I could drag pdf's to and
it automatically save them to YJ, and delete the original pdf. This
could also help me to save time when saving a pdf from safari. I
currently have to save it to the desktop, drag it from desktop to YJ.
Then delete the original file. But in theory if this Folder Action
worked, I could save it from safari straight to this folder and the
import to YJ and the deletion of the file would all happen for me
automatically. I know, I know... this is very lazy of me, but I am
just trying to cut off any extra steps that I can.

Does this make sense? Is there an easier way to do this already? Is
this sort of Folder Action possible? Does it exist already? And if
not, does anyone want to write it for me :-) ?

thanks for your help,

-jonathan

Erik Price

unread,
Feb 6, 2009, 2:33:36 PM2/6/09
to yojimb...@googlegroups.com
On Fri, Feb 6, 2009 at 12:20 PM, Jonathan <jscoo...@gmail.com> wrote:

> Does this make sense? Is there an easier way to do this already? Is
> this sort of Folder Action possible? Does it exist already? And if
> not, does anyone want to write it for me :-) ?

In print dialogs, under the "PDF" submenu, you should be able to save
a PDF directly to Yojimbo without leaving intermediate detritus
anywhere:

http://barebones.com/images/bb1/yojimbo/yojimbo-save-PDF.jpg

e

Jonathan Scoonover

unread,
Feb 6, 2009, 3:00:07 PM2/6/09
to yojimb...@googlegroups.com
Erik,
Yeah, I may not have been clear. Your suggestion works fine for
printing articles or text or pictures while browsing safari. However
it doesn't seem to work when viewing a pdf with safari.

I get an error box stating "Saving a PDF file when printing is not
supported. Instead, choose File > Save. "

I am trying to eliminate the steps of saving the pdf to my downloads
folder. Then adding the pdf to YJ. Then deleting the pdf from the
folder.

For example trying using that technique on this document:

http://barebones.com/store/BBSW_Order_Form.pdf

thanks,
-jonathan

Steve Kalkwarf

unread,
Feb 6, 2009, 3:24:13 PM2/6/09
to yojimb...@googlegroups.com
On Feb 6, 2009, at 3:00 PM, Jonathan Scoonover wrote:
>
> Yeah, I may not have been clear. Your suggestion works fine for
> printing articles or text or pictures while browsing safari. However
> it doesn't seem to work when viewing a pdf with safari.
>
> I get an error box stating "Saving a PDF file when printing is not
> supported. Instead, choose File > Save. "

You have Acrobat installed.

This is one of the many reasons I dislike Acrobat.

Steve

Erik Price

unread,
Feb 6, 2009, 3:22:02 PM2/6/09
to yojimb...@googlegroups.com
On Fri, Feb 6, 2009 at 3:00 PM, Jonathan Scoonover <jscoo...@gmail.com> wrote:
>
> Erik,
> Yeah, I may not have been clear. Your suggestion works fine for
> printing articles or text or pictures while browsing safari. However
> it doesn't seem to work when viewing a pdf with safari.
>
> I get an error box stating "Saving a PDF file when printing is not
> supported. Instead, choose File > Save. "
>
> I am trying to eliminate the steps of saving the pdf to my downloads
> folder. Then adding the pdf to YJ. Then deleting the pdf from the
> folder.
>
> For example trying using that technique on this document:
>
> http://barebones.com/store/BBSW_Order_Form.pdf

I just tried it with that document (I opened that URL in Safari) and
hit Cmd-P, and then from the "PDF" submenu/button chose "Save PDF to
Yojimbo" and it saved to Yojimbo. No errors.

e

Jonathan Scoonover

unread,
Feb 6, 2009, 3:26:45 PM2/6/09
to yojimb...@googlegroups.com
Steve,
I don't use acrobat anymore. I only use preview. Would uninstalling
it fix this? Is a work around possible to create a folder action?

thanks,

-jonathan

Steve Kalkwarf

unread,
Feb 6, 2009, 4:00:07 PM2/6/09
to yojimb...@googlegroups.com
On Feb 6, 2009, at 3:26 PM, Jonathan Scoonover wrote:

> I don't use acrobat anymore. I only use preview. Would uninstalling
> it fix this? Is a work around possible to create a folder action?

Removing Acrobat should fix this.

I haven't written a folder action since the OS 9 days, so I can't
speak with authority, but it seems like an appropriate problem to
solve that way. (Telling Yojimbo to open the pdf will import it, then
you could move the original to the trash)

Another option might be Hazel <http://www.noodlesoft.com/hazel.php>. I
have not used Hazel, but from the product description, it sounds like
it would do what you want (and then some).

Steve

Dennis

unread,
Feb 6, 2009, 4:08:58 PM2/6/09
to yojimb...@googlegroups.com
On Feb 6, 2009, at 1:00 PM, Steve Kalkwarf wrote:

> Another option might be Hazel <http://www.noodlesoft.com/hazel.php>. I
> have not used Hazel, but from the product description, it sounds like
> it would do what you want (and then some).

I heartily recommend Hazel. It's a snap to do this kind of thing with
it. You could have something working in a matter of seconds.

On Feb 6, 2009, at 12:26 PM, Jonathan Scoonover wrote:

> Is a work around possible to create a folder action?


I'm sure a folder action would do the trick as well. So it really
comes down to how much your time is worth and how long it'll take you
to create the folder action. ;-)

-Dennis

Rhet Turnbull

unread,
Feb 6, 2009, 6:22:09 PM2/6/09
to yojimb...@googlegroups.com
>I just tried it with that document (I opened that URL in Safari) and
>hit Cmd-P, and then from the "PDF" submenu/button chose "Save PDF to
>Yojimbo" and it saved to Yojimbo. No errors.

I don't think you really want to do this. It is not equivalent to saving the PDF file into Yojimbo. It runs the PDF through OS X's PDF engine as if you'd printed it. That changes the PDF, changes the author information and other metadata, etc. When I tried it, I also lost the title as well as the URL metadata that Safari adds.

A better solution is what the OP asked for: a script or folder action to store the PDF in Yojimbo. Something like Hazel might also be helpful: http://www.noodlesoft.com/hazel.php

Cheers,
Rhet

Jonathan Scoonover

unread,
Feb 6, 2009, 4:14:05 PM2/6/09
to yojimb...@googlegroups.com
Thank you all for your help. I think I am going to play around with
trying to write a folder action script. And if I can't get it, I will
probably use the suggested Hazel. Thanks again for all of your help
and suggestions!

-jonathan

Erik Price

unread,
Feb 6, 2009, 6:43:09 PM2/6/09
to yojimb...@googlegroups.com
On Fri, Feb 6, 2009 at 6:22 PM, Rhet Turnbull <rtur...@gmail.com> wrote:

> I don't think you really want to do this. It is not equivalent to saving the
> PDF file into Yojimbo. It runs the PDF through OS X's PDF engine as if you'd
> printed it. That changes the PDF, changes the author information and other
> metadata, etc. When I tried it, I also lost the title as well as the URL
> metadata that Safari adds.

If I cared that much about the PDF metadata, then yeah, either a
script or just doing it "by hand" and deleting the intermediate
downloaded file would probably be in order. Generally when I open PDFs
in Safari, however, the metadata in the PDF is the last thing on my
mind.

e

Rhet Turnbull

unread,
Feb 8, 2009, 12:58:51 AM2/8/09
to yojimb...@googlegroups.com
On Fri, Feb 6, 2009 at 11:20 AM, Jonathan <jscoo...@gmail.com> wrote:

I was wondering if anyone has written an applescript (possibly tied to
a folder action) for directly importing pdf's that also deletes the
 
The following script should do you what you want. Open it in Script Editor and save it in ~/Library/Scripts/Folder Action Scripts (you may have to create this folder).  Then make sure folder actions are enabled by running Folder Actions Setup. Then control-click on the folder and select Attach A Folder Action and select the script you just saved.  
Cheers,
Rhet

--Cut here--

--Begin script Move PDF items to Yojimbo

on adding folder items to thisFolder after receiving addedItems

set doLogging to false --set to true to enable logging to the system log

try

repeat with i from 1 to number of items in addedItems

set addedItem to item i of addedItems

set itemInfo to the info for addedItem

if (alias of the itemInfo is false and the file type of the itemInfo is in {"PDF"}) or (the name extension of the itemInfo is in {"pdf"}) then

my syslog(doLogging, "Adding file " & name of the itemInfo)

tell application "Yojimbo"

set theItem to import addedItem

end tell

tell application "Finder" to delete file addedItem

end if

end repeat

on error errMsg number errorNum

if the errorNum is not -128 then

tell application "Finder"

activate

display dialog errMsg buttons {"Cancel"} default button 1 giving up after 120

end tell

end if

end try

end adding folder items to


on syslog(doLog, msgStr)

if (doLog) then

do shell script "/usr/bin/logger " & "'Move PDF items to Yojimbo: " & msgStr & "'"

return result

end if

end syslog


--End script--

--Cut here--


Rhet Turnbull

unread,
Feb 8, 2009, 1:03:45 AM2/8/09
to yojimb...@googlegroups.com
On Fri, Feb 6, 2009 at 3:00 PM, Steve Kalkwarf <kalk...@barebones.com> wrote:

Removing Acrobat should fix this.
 
There are a lot of good reasons to use Acrobat even if it is bloated and annoying. But you don't have to remove Acrobat to remove the Safari plugin. Look in /Library/Internet Plug-Ins and remove the file named something like"Adobe Acrobat Viewer".  I don't recall the exact name.

Cheers,
Rhet

rickdude

unread,
Feb 8, 2009, 10:47:23 PM2/8/09
to Yojimbo Talk
Thanks a lot, Rhett. That's a most useful script. I think perhaps Erik
was talking about PDFs that didn't already exist on one's hard drive,
while Jonathan's questions, and your answers, were about those that
did

On Feb 8, 2:58 pm, Rhet Turnbull <rturnb...@gmail.com> wrote:
> On Fri, Feb 6, 2009 at 11:20 AM, Jonathan <jscoono...@gmail.com> wrote:
>
> > I was wondering if anyone has written an applescript (possibly tied to
> > a folder action) for directly importing pdf's that also deletes the
>
> The following script should do you what you want. Open it in Script Editor
> and save it in ~/Library/Scripts/Folder Action Scripts (you may have to
> create this folder).  Then make sure folder actions are enabled by running
> Folder Actions Setup. Then control-click on the folder and select Attach A
> Folder Action and select the script you just saved.  Cheers,
> Rhet
>
> --*Cut here--*
>
> --*Begin script Move PDF items to Yojimbo*
>
> *on* adding folder items to thisFolder after receiving addedItems
>
> *set* doLogging *to* false --*set to true to enable logging to the system
> log*
>
> *try*
>
> *repeat* *with* i *from* 1 *to* number *of* items *in* addedItems
>
> *set* addedItem *to* item i *of* addedItems
>
> *set* itemInfo *to* *the* info for addedItem
>
> *if* (alias *of* *the* itemInfo *is* false *and* *the* file type *of* *the*
> itemInfo *is* *in* {"PDF"}) *or* (*the* name extension *of* *the* itemInfo *
> is* *in* {"pdf"}) *then*
>
> *my* syslog(doLogging, "Adding file " & name *of* *the* itemInfo)
>
> *tell* application "Yojimbo"
>
> *set* theItem *to* import addedItem
>
> *end* *tell*
>
> *tell* application "Finder" *to* delete file addedItem
>
> *end* *if*
>
> *end* *repeat*
>
> *on* *error* errMsg number errorNum
>
> *if* *the* errorNum *is* *not* -128 *then*
>
> *tell* application "Finder"
>
> activate
>
> display dialog errMsg buttons {"Cancel"} default button 1 giving up after120
>
> *end* *tell*
>
> *end* *if*
>
> *end* *try*
>
> *end* adding folder items to
>
> *on* syslog(doLog, msgStr)
>
> *if* (doLog) *then*
>
> do shell script "/usr/bin/logger " & "'Move PDF items to Yojimbo: " &
> msgStr& "'"
>
> *return* result
>
> *end* *if*
>
> *end* syslog
>
> --*End script--*
>
> --*Cut here--*
Reply all
Reply to author
Forward
0 new messages