kaiuweheinz

Q: AppleScript to create thumbnail of selected file with hyperlink to the URL of the file

Hi,

 

I need an AppleScript to copy to the clipboard a thumbnail of a selected file (s. image 1 below) with a hyperlink to the URL of that selected file. Bildschirmfoto 2016-09-11 um 23.57.44.png

 

I have a script that allows me to get the URL of the selected file and copy it to the clipboard. But then I have to paste the URL in my Document, go back to finder, make a screenshot of the file's thumbnail, paste that screenshot and insert the (manually copied) URL of the file (chosing the context menu of the image) (s. image 2 below):

 

Bildschirmfoto 2016-09-12 um 00.06.31.png

 

Is there a way to automate this?

 

I could make the screenshot manually, that is actually no problem, but then I'd need to attribute this screenshot to a clipboard 1, go back and get the URL of the file and attribute it to clipboard 2 and then go to my document and paste clipboard 1 first, chose the context menu 'hyperlink' and paste clipboard 2.

 

I'd be thankful for help !!

 

(I am a high school language teacher and this is a daylily repetitive task)

 

Regards,

Kai-Uwe

MacBook Air, OS X El Capitan (10.11.6)

Posted on Sep 11, 2016 3:16 PM

Close

Q: AppleScript to create thumbnail of selected file with hyperlink to the URL of the file

  • All replies
  • Helpful answers

Page 1 of 4 last Next
  • by VikingOSX,

    VikingOSX VikingOSX Sep 12, 2016 7:49 AM in response to kaiuweheinz
    Level 7 (20,879 points)
    Mac OS X
    Sep 12, 2016 7:49 AM in response to kaiuweheinz

    Kai-Uwe,

     

    OpenOffice, or LibreOffice are not externally scriptable with AppleScript, or Automator, as these two applications exclude that support. They are internally Python scriptable via their respective SDK.

     

    I have become aware of an AppleScript solution that prompts for the input file, and then uses a custom (pre-compiled) application that uses QuickLook to generate a jpg thumbnail image to your specified output destination. I added one line of AppleScript that sends the file URL onto the clipboard.

     

    After the script runs, I can paste the document URL into LibreOffice, and follow this by a drag/drop the jpg thumbnail afterwards.

    Screen Shot 2016-09-12 at 10.32.56 AM.jpg

    Do you want me to post the particulars for this solution. In its current form, it is not written for batch processing.

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 12, 2016 9:05 AM in response to VikingOSX
    Level 1 (8 points)
    Mac OS X
    Sep 12, 2016 9:05 AM in response to VikingOSX

    Dear VikingOSX,

     

    thank you for dealing with my problem. Selecting a file in the finder is a vital approach for me: the first step in preparing a lesson is to collect all necessary files, once I have done that I can rearrange the order and elaborate the rest of the lesson.

     

    So it would be perfect if the Script worked in finder so that I could copy the hyperlinked thumbnail to the clipboard regardless of whether I paste it into Word, OpenOffice or other program. If this however is not possible, then a script that will paste first the jpg thumbnail then the file URL would be of great help.

     

    If you could post the particulars for getting the jpg thumbnails, it would help a lot. Would a batch processing enable me to select multiple files in finder with result that with cmd+V I can paste them one below the other? That would save even more time.

     

    Thank you in advance for posting the particulars.

     

    NB: I know how to retrieve the URL of a file selected in finder.

           I want to know how to retrieve the JPG thumbnail of a selected file.

           I would love to combine the two steps.

     

    Thank you so much in advance,

    Kai-Uwe

  • by VikingOSX,

    VikingOSX VikingOSX Sep 12, 2016 2:26 PM in response to kaiuweheinz
    Level 7 (20,879 points)
    Mac OS X
    Sep 12, 2016 2:26 PM in response to kaiuweheinz

    I believe it is possible for you to select multiple documents, accumulate their file URI and generated jpeg thumbnails in a meta-document, and then convert that meta-document into Word docx, or LibreOffice odt documents. Then you just open the final document. No copy/paste of any kind is necessary.

     

    I believe that I can achieve all of the above with an AppleScript that begins by prompting you for multiple document selections, and then it does all of the processing to the final Word or LO document. I have to make some changes to the AppleScript as it is currently written, and perform some additional testing.

     

    Probably ready by 13 Sept if I am undistracted.

  • by VikingOSX,

    VikingOSX VikingOSX Sep 13, 2016 1:53 PM in response to kaiuweheinz
    Level 7 (20,879 points)
    Mac OS X
    Sep 13, 2016 1:53 PM in response to kaiuweheinz

    The following AppleScript prompts you for file(s) from which to generate thumbnail images using the Quick Look Manager (qlmanage) utility that ships with OS X. As it generates the thumbnails, it writes LaTeX syntax into a metafile consisting of each document file URI, and the path to the image. This solution does not require installation of TeX, or LaTeX distribution, or knowledge of them, to produce results.

     

    When done, it uses Pandoc to translate the LaTeX metafile into Word .docx, or OpenDocument Format .odt documents.  The metafile is deleted and recreated with each run of the AppleScript. Here is a screen shot of the finished Word document in LibreOffice 5.2.1.2 (click to enlarge).

    Screen Shot 2016-09-13 at 3.39.28 PM.jpg

    The AppleScript will introduce a newpage into the metafile after every four images. There is a manpage for qlmanage, and it also responds to qlmanage -h in the Terminal.

     

    The only item you will need install is Pandoc. The cleanest way to install it is with the Homebrew package manager, and then you install pandoc as (type in blue):

    # This will install pandoc as /usr/local/bin/pandoc

    $ brew install pandoc

    About every two weeks, I do the following to keep homebrew and applications up to date:

    $ brew update

    $ brew upgrade

     

    The AppleScript:

    property default_loc : ((path to desktop) as text) as alias

    property qmesg : "Choose file(s) to generate thumbnails"

    property metafile : (path to desktop as text) & "meta.tex"

    property thumbpath : (path to desktop as text) & "Thumbs:"

    property fileCnt : missing value

     

    tell application "Finder"

         if exists file metafile then

              delete file metafile

         end if

         if not (exists folder thumbpath) = true then

              make new folder at (path to desktop as text) with properties {name:"Thumbs"}

         end if

    end tell

    -- create the empty metafile and return a file handle used to write to it

    set fRef to openMetaFile(metafile)

    -- initialize with the preamble LaTeX stuff

    init_metadata(fRef)

     

    set inPath to (choose file with prompt qmesg default location default_loc with multiple selections allowed without invisibles and showing package contents)

     

    set fileCnt to (count of inPath)

    repeat with afile in inPath

         tell application "Finder"

              set ImgPath to ""

              set theURL to (afile's URL) as text

              set theImgName to afile's name & ".png"

              set ImgPath to POSIX path of (thumbpath & theImgName)

              set inFile to (afile's POSIX path)'s quoted form

         end tell

         try write_metadata(fRef, theURL, ImgPath)

              -- use the QuickLook manager to generate a 128 pixel icon at 90% scale

              do shell script "/usr/bin/qlmanage -tif 0.9 -s 128 " & inFile & " -o " & POSIX path of thumbpath & " >& /dev/null"

         on error errmsg number errnbr

              my error_handler(errnbr, errmsg)

              set fileCnt to 0

              return

         end try

    end repeat

    write "\\end{document}" & linefeed to fRef starting at eof

    close access fRef

    -- do shell script "/usr/local/bin/pandoc -s -f latex -o ~/Desktop/work.odt " & POSIX path of metafile

    do shell script "/usr/local/bin/pandoc -s -f latex -o ~/Desktop/work.docx " & POSIX path of metafile

    display dialog (fileCnt as text) & " records written. Document produced."

    set fileCnt to 0

    return

     

    on openMetaFile(filePath)

         -- influenced by twtwtw from https://discussions.apple.com/thread/4256380?tstart=0

         try

              set fp to (open for access file filePath with write permission)

         on error errmsg number errnbr

              if errnbr = -49 then

                   close access filePath

                   set fp to (open for access filePath with write permission)

              else

                   my error_handler(errnbr, errmsg)

                   return false

              end if

         end try

      return fp

    end openMetaFile

     

    on init_metadata(fh)

         -- latex preamble

         write "\\documentclass[10pt, twocolumn]{article}" & linefeed to fh starting at eof

         write "\\usepackage{url}" & linefeed to fh starting at eof

         write "\\usepackage{graphicx}" & linefeed to fh starting at eof

         write "\\" & linefeed to fh starting at eof

         write "\\setmainfont{Helvetica}" & linefeed to fh starting at eof

         write "\\begin{document}" & linefeed to fh starting at eof

         return

    end init_metadata

     

    on write_metadata(fh, aURL, imagePath)

         -- attempt to control quantity of images on a page

         set imagecnt to (do shell script "[[ -s " & metafile & " ]] && egrep -c includegraphics " & metafile & " || echo \"0\"") as integer

         -- every four images we introduce a new page

         if imagecnt > 0 and ((imagecnt mod 4) as integer) = 0 and imagecnt < fileCnt then

              write "\\newpage" & linefeed to fh starting at eof

         end if

         -- write data to it

         write "\\url{" & aURL & "}" & linefeed to fh starting at eof

         write "\\\\\\\\" & linefeed to fh starting at eof

         write "\\includegraphics{" & imagePath & "}" & linefeed to fh starting at eof

         write "\\\\\\\\" & linefeed to fh starting at eof

         return

    end write_metadata

     

    on error_handler(nbr, msg)

         return display alert "[ " & nbr & " ] " & msg as critical giving up after 10

    end error_handler

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 13, 2016 2:16 PM in response to VikingOSX
    Level 1 (8 points)
    Mac OS X
    Sep 13, 2016 2:16 PM in response to VikingOSX

    Dear VIKING OSX,

     

    I am deeply impressed! You are such a generous person investing so much time in dealing with my problem. I've already installed 'basicTex' and 'PanDoc'. While saving your Script however I encountered the following dialogue:

     

    Bildschirmfoto 2016-09-13 um 23.08.33.png

    which translated means: "syntax error - expected end of line , but found identifier". What would you suggest?

     

    Thank you so much in advance, kind regards,

    Kai-Uwe

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 13, 2016 2:46 PM in response to VikingOSX
    Level 1 (8 points)
    Mac OS X
    Sep 13, 2016 2:46 PM in response to VikingOSX

    Dear VIKING OSX,

     

    I am deeply impressed! You are such a generous person investing so much time in dealing with my problem. I've already installed 'basicTex' and 'PanDoc'. While playing your Script however I encountered the following dialogue:

    Bildschirmfoto 2016-09-13 um 23.38.17.png

     

    which translated means: ' "script error - "Macintosh HD:Users:kai-Uwe:Desktop:meta.tex" cannot be transformed into  Typ file.' What would you suggest? On top of that: How can

     

    Thank you so much in advance, kind regards,

    Kai-Uwe

  • by Camelot,

    Camelot Camelot Sep 13, 2016 2:53 PM in response to kaiuweheinz
    Level 8 (47,285 points)
    Mac OS X
    Sep 13, 2016 2:53 PM in response to kaiuweheinz

    There should be a return between the 'try' and 'write_metadata' words on this line:

     

         try write_metadata(fRef, theURL, ImgPath)


    e.g.:


         try

              write_metadata(fRef, theURL, ImgPath)


  • by Camelot,

    Camelot Camelot Sep 13, 2016 2:55 PM in response to kaiuweheinz
    Level 8 (47,285 points)
    Mac OS X
    Sep 13, 2016 2:55 PM in response to kaiuweheinz

    I think the line:

     

    close access filePath

     

    should be:

     

    close access fp

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 13, 2016 3:03 PM in response to Camelot
    Level 1 (8 points)
    Mac OS X
    Sep 13, 2016 3:03 PM in response to Camelot

    Thank you for your help while the return after try helped a lot, I still encountered this dialogue:

    Bildschirmfoto 2016-09-14 um 00.01.52.png

    which literally translated means: "Script error. The variable 'fp' is not defined."

     

    Do you have other suggestions?

     

    Thank you in advance,

    Kai-Uwe

  • by Hiroto,

    Hiroto Hiroto Sep 13, 2016 3:34 PM in response to kaiuweheinz
    Level 5 (7,286 points)
    Sep 13, 2016 3:34 PM in response to kaiuweheinz

    Hello

     

    Here's another AppleScript script you might try. It is a simple wrapper of pyobjc script which creates html document of hyperlinked thumbnails of selected files using QuickLook framework function. Output is given in two forms – one is data in the clipboard that you can paste to destination and another is html file, currently ~/Desktop/out.html, that you can open by web browser.

     

    As far as I have tested with LibreOffice 4.3.7.2 under OS X 10.6.8, I can paste the resulting clipboard content to Writer document. However, some applications do not paste html data in the clipboard, in which case you may open the html file and copy data from there.

     

    Currently the thumbnail size is set to 512 x 512 pixels. You can specify the size in IMAGE_SIZE variable in python code.

     

     

    --APPLESCRIPT
    tell application "Finder"
        set ff to selection as alias list
    end tell
    set args to ""
    repeat with a in ff
        set args to args & a's POSIX path's quoted form & space
    end repeat
    
    do shell script "/usr/bin/python <<'EOF' - " & args & " > ~/Desktop/out.html
    # coding: utf-8
    # 
    #   file:
    #       qlthumbnail.py
    # 
    #   function:
    #       print html document of hyperlinked thumbnail(s) of given file(s) and put the document in the clipboard
    # 
    #   usage:
    #       qlthumbnail.py file [file ...]
    # 
    #   version:
    #       0.10
    #           - draft
    # 
    #   written by Hiroto, 2016-09
    # 
    import sys, os, objc
    import base64, re
    from Quartz.CoreGraphics import *   # required for QLThumbnailImageCreate() using CG symbols
    from AppKit import *
    
    QL_BRIDGESUPPORT = '''<?xml version=\"1.0\" standalone=\"yes\"?>
    <!DOCTYPE signatures SYSTEM \"file://localhost/System/Library/DTDs/BridgeSupport.dtd\">
    <signatures version=\"0.9\">
       <constant type=\"^{__CFString=}\" name=\"kQLThumbnailOptionIconModeKey\"></constant>
        <constant type=\"^{__CFString=}\" name=\"kQLThumbnailOptionScaleFactorKey\"></constant>
        <function name=\"QLThumbnailImageCreate\">
            <arg type=\"^{__CFAllocator=}\"></arg>
            <arg type=\"^{__CFURL=}\"></arg>
            <arg type=\"{CGSize=ff}\" type64=\"{CGSize=dd}\"></arg>
            <arg type=\"^{__CFDictionary=}\"></arg>
            <retval type=\"^{CGImage=}\"></retval>
        </function>
    </signatures>'''
    
    objc.parseBridgeSupport(
        QL_BRIDGESUPPORT, 
        globals(),
        objc.pathForFramework('/System/Library/Frameworks/QuickLook.framework')
    )
    
    def html_escape(s):
        s = re.sub(r'&', '&amp;', s)
        s = re.sub(r'<', '&lt;', s)
        s = re.sub(r'>', '&gt;', s)
        return s
    
    def main():
        # html opening
        s = u'''<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
    <html>
    <head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></head>
    <body>'''
    
        # html entry template
        tmpl = u'''
    <p>~</p>
    <p>%s</p>
    <p>
    <a href=\"%s\">
    <img src=\"data:%s;base64,%s\" />
    </a>
    </p>
    '''
        for f in [ a.decode('utf-8') for a in sys.argv[1:] ]:
            iurl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, f.encode('utf-8'), len(f.encode('utf-8')), False)
            cgi = QLThumbnailImageCreate(
                kCFAllocatorDefault,
                iurl,
                CGSizeMake(*IMAGE_SIZE),
                { kQLThumbnailOptionIconModeKey : kCFBooleanTrue }
            )
            if cgi:
                brep = NSBitmapImageRep.alloc().initWithCGImage_(cgi)
                data = brep.representationUsingType_properties_(NSJPEGFileType, {})
                byts = data.getBytes_length_(None, data.length())
                b64s = base64.b64encode(byts)
            else:
                b64s = ''
    
            # append html entry for this file
            s += tmpl % (html_escape(iurl.path()), iurl.absoluteString(),'image/jpeg', b64s)
    
        # html closing
        s += u'</body></html>'
        
        # print html
        print s.encode('utf-8')
    
        # put html data in clipboard
        html = NSString.stringWithString_(s).dataUsingEncoding_(NSUTF8StringEncoding)
        pboard = NSPasteboard.generalPasteboard()
        pbtype = 'public.html'
        pboard.declareTypes_owner_([pbtype], None)
        pboard.setData_forType_(html, pbtype)
    
    IMAGE_SIZE = (512.0, 512.0)
    main()
    EOF"
    --END OF APPLESCRIPT
    

     

     

    ---

    And here's original python script if you prefer using it in shell.

     

     

    #!/usr/bin/python
    # coding: utf-8
    # 
    #   file:
    #       qlthumbnail.py
    # 
    #   function:
    #       print html document of hyperlinked thumbnail(s) of given file(s) and put the document in the clipboard
    # 
    #   usage:
    #       qlthumbnail.py file [file ...]
    # 
    #   version:
    #       0.10
    #           - draft
    # 
    #   written by Hiroto, 2016-09
    # 
    import sys, os, objc
    import base64, re
    from Quartz.CoreGraphics import *   # required for QLThumbnailImageCreate() using CG symbols
    from AppKit import *
    
    QL_BRIDGESUPPORT = '''<?xml version="1.0" standalone="yes"?>
    <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
    <signatures version="0.9">
       <constant type="^{__CFString=}" name="kQLThumbnailOptionIconModeKey"></constant>
        <constant type="^{__CFString=}" name="kQLThumbnailOptionScaleFactorKey"></constant>
        <function name="QLThumbnailImageCreate">
            <arg type="^{__CFAllocator=}"></arg>
            <arg type="^{__CFURL=}"></arg>
            <arg type="{CGSize=ff}" type64="{CGSize=dd}"></arg>
            <arg type="^{__CFDictionary=}"></arg>
            <retval type="^{CGImage=}"></retval>
        </function>
    </signatures>'''
    
    objc.parseBridgeSupport(
        QL_BRIDGESUPPORT, 
        globals(),
        objc.pathForFramework('/System/Library/Frameworks/QuickLook.framework')
    )
    
    def html_escape(s):
        s = re.sub(r'&', '&amp;', s)
        s = re.sub(r'<', '&lt;', s)
        s = re.sub(r'>', '&gt;', s)
        return s
    
    def main():
        # html opening
        s = u'''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head>
    <body>'''
    
        # html entry template
        tmpl = u'''
    <p>~</p>
    <p>%s</p>
    <p>
    <a href="%s">
    <img src="data:%s;base64,%s" />
    </a>
    </p>
    '''
        for f in [ a.decode('utf-8') for a in sys.argv[1:] ]:
            iurl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, f.encode('utf-8'), len(f.encode('utf-8')), False)
            cgi = QLThumbnailImageCreate(
                kCFAllocatorDefault,
                iurl,
                CGSizeMake(*IMAGE_SIZE),
                { kQLThumbnailOptionIconModeKey : kCFBooleanTrue }
            )
            if cgi:
                brep = NSBitmapImageRep.alloc().initWithCGImage_(cgi)
                data = brep.representationUsingType_properties_(NSJPEGFileType, {})
                byts = data.getBytes_length_(None, data.length())
                b64s = base64.b64encode(byts)
            else:
                b64s = ''
    
            # append html entry for this file
            s += tmpl % (html_escape(iurl.path()), iurl.absoluteString(),'image/jpeg', b64s)
    
        # html closing
        s += u'</body></html>'
        
        # print html
        print s.encode('utf-8')
    
        # put html data in clipboard
        html = NSString.stringWithString_(s).dataUsingEncoding_(NSUTF8StringEncoding)
        pboard = NSPasteboard.generalPasteboard()
        pbtype = 'public.html'
        pboard.declareTypes_owner_([pbtype], None)
        pboard.setData_forType_(html, pbtype)
    
    IMAGE_SIZE = (512.0, 512.0)
    main()
    

     

     

     

    Scripts are briefly tested with pyobjc 2.2b3 and python 2.6.1 under OS X 10.6.8.

     

    * PyObjC is part of standard installation of OS X 10.5 through 10.11.

     

    Good luck,

    H

  • by VikingOSX,

    VikingOSX VikingOSX Sep 13, 2016 4:12 PM in response to kaiuweheinz
    Level 7 (20,879 points)
    Mac OS X
    Sep 13, 2016 4:12 PM in response to kaiuweheinz

    I think that you picked up some formatting errors in your copy/paste that were not in the original code that I posted.

     

    Camelot is correct about their needing to be a return between the try and the write_metadata function.

     

    If you run into the situation where it cannot write the metadata.tex file out. Save and quit your script, and remove the metadata.tex file from your Desktop, and then empty the Trash. Then re-run the AppleScript. This is an occasional issue that I have here too, and it isn't sorted yet.

     

    Camelot is also correct about changing the close access filepath to close access fp.

  • by VikingOSX,

    VikingOSX VikingOSX Sep 13, 2016 4:36 PM in response to kaiuweheinz
    Level 7 (20,879 points)
    Mac OS X
    Sep 13, 2016 4:36 PM in response to kaiuweheinz

    I am on OS X 10.11.6. I have just run the same AppleScript that I posted — five times in a row with single, or multiple documents chosen each time — and the script runs to normal conclusion with a Word document outcome as expected.

     

    Hope you can get it sorted as I think it will save you considerable time without the need of the clipboard.

  • by Hiroto,

    Hiroto Hiroto Sep 14, 2016 5:56 AM in response to kaiuweheinz
    Level 5 (7,286 points)
    Sep 14, 2016 5:56 AM in response to kaiuweheinz

    Hello

     

    You may simply replace the original openMetaFile() handler with the following one:

     

    on openMetaFile(filePath)
        return (open for access file filePath with write permission)
    end openMetaFile
    

     

     

    If it throws error -49 opWrErr (File already open for writing), restart Script Editor to close any file handle left open.

     

    Good luck,

    H

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 14, 2016 12:05 PM in response to Hiroto
    Level 1 (8 points)
    Mac OS X
    Sep 14, 2016 12:05 PM in response to Hiroto

    Thank you all very much for the amendments suggested.

     

    Dear VikingOSX,

    I followed thoroughly your pieces of advice. However I continually get the following feedback:

    Bildschirmfoto 2016-09-14 um 19.46.49.png

    when - having deleted meta.tex and (after having closed the ScriptEditor) emptied the trashcan -

    while running the following script:

     

    property default_loc : ((path to desktop) as text) as alias

    property qmesg : "Choose file(s) to generate thumbnails"

    property metafile : (path to desktop as text) & "meta.tex"

    property thumbpath : (path to desktop as text) & "Thumbs:"

    property fileCnt : missing value

     

    tell application "Finder"

         if exists file metafile then

              delete file metafile

         end if

         if not (exists folder thumbpath) = true then

              make new folder at (path to desktop as text) with properties {name:"Thumbs"}

         end if

    end tell

    -- create the empty metafile and return a file handle used to write to it

    set fRef to openMetaFile(metafile)

    -- initialize with the preamble LaTeX stuff

    init_metadata(fRef)

     

    set inPath to (choose file with prompt qmesg default location default_loc with multiple selections allowed without invisibles andshowing package contents)

     

    set fileCnt to (count of inPath)

    repeat with afile in inPath

         tell application "Finder"

              set ImgPath to ""

              set theURL to (afile's URL) as text

              set theImgName to afile's name & ".png"

              set ImgPath to POSIX path of (thumbpath & theImgName)

              set inFile to (afile's POSIX path)'s quoted form

         end tell

         try write_metadata(fRef, theURL, ImgPath)

              -- use the QuickLook manager to generate a 128 pixel icon at 90% scale

              do shell script "/usr/bin/qlmanage -tif 0.9 -s 128 " & inFile & " -o " & POSIX path of thumbpath & " >& /dev/null"

         on error errmsg number errnbr

              my error_handler(errnbr, errmsg)

              set fileCnt to 0

              return

         end try

    end repeat

    write "\\end{document}" & linefeed to fRef starting at eof

    close access fRef

    -- do shell script "/usr/local/bin/pandoc -s -f latex -o ~/Desktop/work.odt " & POSIX path of metafile

    do shell script "/usr/local/bin/pandoc -s -f latex -o ~/Desktop/work.docx " & POSIX path of metafile

    display dialog (fileCnt as text) & " records written. Document produced."

    set fileCnt to 0

    return

     

    on openMetaFile(filePath)

         -- influenced by twtwtw from https://discussions.apple.com/thread/4256380?tstart=0

         try

              set fp to (open for access file filePath with write permission)

         on error errmsg number errnbr

              if errnbr = -49 then

                   close access filePath

                   set fp to (open for access filePath with write permission)

              else

                   my error_handler(errnbr, errmsg)

                   return false

              end if

         end try

      return fp

    end openMetaFile

     

    on init_metadata(fh)

         -- latex preamble

         write "\\documentclass[10pt, twocolumn]{article}" & linefeed to fh starting at eof

         write "\\usepackage{url}" & linefeed to fh starting at eof

         write "\\usepackage{graphicx}" & linefeed to fh starting at eof

         write "\\" & linefeed to fh starting at eof

         write "\\setmainfont{Helvetica}" & linefeed to fh starting at eof

         write "\\begin{document}" & linefeed to fh starting at eof

         return

    end init_metadata

     

    on write_metadata(fh, aURL, imagePath)

         -- attempt to control quantity of images on a page

         set imagecnt to (do shell script "[[ -s " & metafile & " ]] && egrep -c includegraphics " & metafile & " || echo \"0\"") as integer

         -- every four images we introduce a new page

         if imagecnt > 0 and ((imagecnt mod 4) as integer) = 0 and imagecnt < fileCnt then

              write "\\newpage" & linefeed to fh starting at eof

         end if

         -- write data to it

         write "\\url{" & aURL & "}" & linefeed to fh starting at eof

         write "\\\\\\\\" & linefeed to fh starting at eof

         write "\\includegraphics{" & imagePath & "}" & linefeed to fh starting at eof

         write "\\\\\\\\" & linefeed to fh starting at eof

         return

    end write_metadata

     

    on error_handler(nbr, msg)

         return display alert "[ " & nbr & " ] " & msg as critical giving up after 10

    end error_handler

     

     

    Do you have any further idea? What would one need to add for the Script to open the output .odt file automatically in OpenOffice (allowing me to immediately copy and paste the result into my OpenOffice lesson protocol?

     

    Thank you truly for any advice, gratefully,

    Kai-Uwe

     

     

     

    Dear Hiroto,

     

    thank you very much for adding another approach! Your solution would also suit me perfectly as pasting the result is quicker then going to the desktop folder and opening the output file but while the output file "out.hml" works as it should - thanks again! -, I get the following result when pasting the clipboard in OpenOffice:

    Bildschirmfoto 2016-09-14 um 20.09.12.png

    and

    Bildschirmfoto 2016-09-14 um 20.11.23.png

    when pasting in MS Word.

     

    Even when opening the out.hml file within OpenOffice and word I get quite the same results:

     

    Bildschirmfoto 2016-09-14 um 20.47.42.png

    (Openoffice)

     

    Bildschirmfoto 2016-09-14 um 20.49.50.png

    (word)

     

     

    Do you have any suggestions?

     

    In OpenOffice I saw that the image is treated as a "linked" image ('Verknüpfung') not as an image "stored locally". Could that be the reason the word processing programs don't manage to display the thumbnails correctly?

     

    I daylily teach various classes always using OpenOffice which I am very familiar with and which allows me to export each lesson's protocol as a PDF and send it to each student via e-mail (a gesture appreciated by many, even the parents), so the ability to visually integrate the thumbnails in OpenOffice and thus visually include them in the protocol would have many advantages:

    - when a student has lost a given work sheet, he/she can come up to me and say: I need this work sheet and point to it visually. With one click I can click on the thumbnail and print the requested sheet. 

    - in the protocol the students receive at home via e-mail, they can also retrieve the homework announced during the lesson, they could visually see what exact sheet they are meant to work on. Now they often come the next day with excuses like "Oh, I thought you meant the other sheet". Such misunderstandings would be eliminated.

     

    To make your solution 'as it is' work for me I would need to insert a link to each protocol's out.hml so that during the lesson I can quickly open the various sheets. This is not practical so far.

     

    When I convert the out.html file to a PDF and open it in OpenOffice I do get the thumbnails but without hyperlink. Even the written path isn't clickable anymore. So this either isn't a practical solution.

     

    Bildschirmfoto 2016-09-14 um 20.57.53.png

     

    And if I had a Script to simply retrieve the thumbnail pic that would save it to the clipboard and I would first paste the thumbnail and after that the path as I suggested in my first post ? Would that be possible? Is there a function to simply save the QuickLook thumbnail to the clipboard?

     

     

    Whatever will come out of all your efforts it will serve many language students over here in Germany. So, again, thank you all soo much for going through this with me.

     

    Kai-Uwe

Page 1 of 4 last Next