How to automate PDFpen with applkescript

Discussion in 'Mac Programming' started by josecarioca, Dec 22, 2013.

  1. josecarioca, Dec 22, 2013
    Last edited by a moderator: Dec 22, 2013

    josecarioca macrumors newbie

    Joined:
    Dec 21, 2013
    Location:
    Sardinia - Italy
    #1
    I'm a debutant to this forum. I am not able to complete this script to automate conversion of few image files (jpg) to PDF, with PDFpen application. First it should be run for a single file, afterwards I will adapt it to most files.
    Could anyone suggest me the missing instructions for?
    Thanks
    Mario

    Code:
    on run
    	set MioOcr to "PDFpen"
    	set cartella to ("HDmio:JPGsPROVE:")
    	set filmio to (cartella & "immagine-1.jpg")
    	tell application MioOcr
    		open filmio --     OK : it opens image with PDFpen
    		
    		--            Here statments to continue      
    		--   key  : Document OCR (to execute conversion)
    		--   key  : save as :   ....    (filename, folder, format)
    		--   key  : close file
    	end tell
    end run
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Why not save yourself the trouble and do this in Automator with the New PDF From Images action.
     

    Attached Files:

  3. josecarioca thread starter macrumors newbie

    Joined:
    Dec 21, 2013
    Location:
    Sardinia - Italy
    #3
    Thanks Kryten2,
    but suggested solution with Automator gives me a Pdf file not sercheable (type image only), contrariwise I need a PDF where I can make reserches on words. And PDFpen satisfies theese my needs.
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Ok, now I see why you used PDFpen. Here's an example for one file.


    Code:
    set theFile to choose file default location path to documents folder
    set theFileName to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of (theFile as text)
    
    tell application "PDFpenPro"
    	-- insert actions here
    	activate
    	open theFile
    	tell document 1
    		ocr
    		repeat while performing ocr
    			delay 1
    		end repeat
    		delay 1
    		save in file ("MavericksDP:Users:kryten:" & theFileName)
    		close
    	end tell
    end tell
    
    Info and example scripts : here and pdfpen-ocr-applescript-to-automatically-make-pdfs-searchable/ and pdfpen-ocr-folder-action-script.html
     
  5. josecarioca thread starter macrumors newbie

    Joined:
    Dec 21, 2013
    Location:
    Sardinia - Italy
    #5
    :) I thank you infinitely for your kindness. It seems to work fine, except for some error probably due to my mistakes in data entry.
    Now I have to minutely examine script you sent me. For now, thank you so much and be pleased with best wishes for Christmas and happy New Year!
    Mario
     
  6. josecarioca thread starter macrumors newbie

    Joined:
    Dec 21, 2013
    Location:
    Sardinia - Italy
    #6
    hi Kryten2,
    could you explain me the meaning of the following command included into script you sent me ?

    set theFileName to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of (theFile as text)

    Thanks in advance
     
  7. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    It should return the filename without the extension you get from the first line in the script e.g. set theFile to choose file ... So for example if your file is named Holiday.jpg then the value of theFileName variable would be "Holiday". It was merely given as an example. Feel free to name your file(s) however you like.
     
  8. josecarioca thread starter macrumors newbie

    Joined:
    Dec 21, 2013
    Location:
    Sardinia - Italy
    #8
    Thank you so much again.
    I understood what the string you sent me makes, but I wanted to understand how script string get the result. Particularly, I realized that '-E' indicates 'editing' and 's' means 'substitute'. But not the part of the string where are the characters '|' (I think those are delimiters. I read delimiters should only be 3 and so I get confused).
    Also I can not understand the last part of the command 'sed' (ie '<<< ") and the final part of the string (ie' & quoted form of (the file as text)).
    I know I'm asking too much, so if I'm boring, you can easily not answer: thank you anyway.
    By the way do you understand Italian language ? It would be easier for me to explain..
    Mario
     

Share This Page