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

first Previous Page 3 of 4 last Next
  • by Hiroto,

    Hiroto Hiroto Sep 15, 2016 4:18 AM in response to kaiuweheinz
    Level 5 (7,306 points)
    Sep 15, 2016 4:18 AM in response to kaiuweheinz

    Hello

     

    You cannot copy content from Safari window of out.html to LibreOffice Writer document because Safari does not put html data but rtfd and webarchive data in the clipboard. LibreOffice pastes html data and neither rtfd nor webarchive data. (Meanwhile you can copy from Firefox window because it puts html data in the clipboard)

     

    So when using LibreOffice, just run the script and paste the clipboard content prepared by the script to LibreOffice Writer document.

     

    I tested this with LibreOffice 4.3.7.2 under OS X 10.6.8.

     

    Regards,

    H

     

    PS. As for the path string above thumnail image in my output, it is mere string without any URL associated. If you want it being active link, it is easy to ammend script accordingly although I think hyperlinked thumbnail is what you want.

  • by Hiroto,

    Hiroto Hiroto Sep 15, 2016 4:37 AM in response to kaiuweheinz
    Level 5 (7,306 points)
    Sep 15, 2016 4:37 AM in response to kaiuweheinz

    As for TextEdit selecting target file in Finder when clicking link with file URL, I think it is as designed becausue I observe the same under OS X 10.6.8. However, this test is to see if TextEdit can paste html data in the clipboard correctly and now we know it does.

     

    Your observations on copying rich text content from TextEdit document to OpenOffice Writer (or NeoOffice Writer) indicate OO/NO Writer cannot paste rtfd data in the clipboard either. Now we need other way to tame it...

     

    H

  • by VikingOSX,

    VikingOSX VikingOSX Sep 15, 2016 6:20 AM in response to kaiuweheinz
    Level 7 (21,014 points)
    Mac OS X
    Sep 15, 2016 6:20 AM in response to kaiuweheinz

    The pandoc program expects its input meta.tex file to be in UTF-8 encoding, and when it is not, you will get that invalid UTF-8 stream error. This was an oversight on my behalf, as one can force the AppleScript write statements to generate UTF-8 content, and this will percent encode certain characters (e.g. ü to %CC%88) in filenames.

     

    I decided to post another edition of my AppleScript with these UTF-8 output corrections, and you can confirm the output in the Terminal:

    $ file --mime-encoding meta.tex

     

    Code:

     

    -- qlthumb.applescript

    -- Prompt user for files and write LaTeX metadata that is transformed into

    -- DOCX or ODT documents via third-party pandoc utility

    -- Version 1.3, Updated write statements to force UTF-8 encoding for Pandoc

    -- VikingOSX, Sept 14, 2016, Apple Support Communities

     

    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 mfile : POSIX path of metafile

    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 as «class utf8»

    close access fRef

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

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

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

    set fileCnt to (0 as integer)

    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 fp

      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 as «class utf8»

      write "\\usepackage{url}" & linefeed to fh starting at eof as «class utf8»

      write "\\usepackage{graphicx}" & linefeed to fh starting at eof as «class utf8»

      write "\\" & linefeed to fh starting at eof as «class utf8»

      write "\\setmainfont{Helvetica}" & linefeed to fh starting at eof as «class utf8»

      write "\\begin{document}" & linefeed to fh starting at eof as «class utf8»

      return

    end init_metadata

     

    on write_metadata(fh, aURL, imagePath)

     

      -- attempt to control quantity of images on a page

      try

      set imagecnt to (do shell script "grep -c 'includegraphics' " & mfile) as integer

      on error

      -- avoid issue where match above fails and returns "0"

      set imagecnt to 0 as integer

      end try

      -- every four images we introduce a new page

      log imagecnt

      if imagecnt > "0" then

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

      write "\\newpage" & linefeed to fh starting at eof as «class utf8»

      end if

      end if

     

      -- write data to it

      write "\\url{" & aURL & "}" & linefeed to fh starting at eof as «class utf8»

      write "\\\\\\\\" & linefeed to fh starting at eof as «class utf8»

      write "\\includegraphics{" & imagePath & "}" & linefeed to fh starting at eof as «class utf8»

      write "\\\\\\\\" & linefeed to fh starting at eof as «class utf8»

     

      return

     

    end write_metadata

     

    on error_handler(nbr, msg)

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

    end error_handler

  • by Hiroto,

    Hiroto Hiroto Sep 15, 2016 10:59 AM in response to kaiuweheinz
    Level 5 (7,306 points)
    Sep 15, 2016 10:59 AM in response to kaiuweheinz

    Hello

     

    The folowing table is the summary of copy-paste capabilities as I understand.

     

     

    source      ->  (clipboard)         ->  destination
    -----------------------------------------
    my script   ->  (html)              ->  LibreOffice Writer  OK
    my script   ->  (html)              ->  OpenOffice Writer   # NG
    my script   ->  (html)              ->  NeoOffice Writer    # NG
    
    my script   ->  (html)              ->  TextEdit rich text  OK
    TextEdit    ->  (rtfd)              ->  LibreOffice Writer  # NG
    TextEdit    ->  (rtfd)              ->  OpenOffice Writer   # NG
    TextEdit    ->  (rtfd)              ->  NeoOffice Writer    # NG
    
    Firefox     ->  (html)              ->  LibreOffice Writer  OK
    Firefox     ->  (html)              ->  OpenOffice Writer   # NG
    Firefox     ->  (html)              ->  NeoOffice Writer    # NG
    
    Safari      ->  (rtfd, webarchive)  ->  LibreOffice Writer  # NG
    Safari      ->  (rtfd, webarchive)  ->  OpenOffice Writer   # NG
    Safari      ->  (rtfd, webarchive)  ->  NeoOffice Writer    # NG
    
    
    * Tested with LibreOffice 4.3.7.2 under OS X 10.6.8. 
      (OpenOffice and NeoOffice results are by your report)
    

     

     

    So your options would be -

     

    a) paste html data put in the clipboard by my script to LibreOffice Writer document, save the document as odt and open it in NeoOffice; or

     

    b) open html file created by my script in Firefox, copy the content, paste it into LibreOffice Writer document, save the document as odt and open it in NeoOffice.

     

     

     

    ----

    By the way, I revised my script a little so that the path string in output is now active link.

     

     

    --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 html data in the clipboard
    # 
    #   usage:
    #       qlthumbnail.py file [file ...]
    # 
    #   version:
    #       0.10a
    #           - added anchor element for path string
    #       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><a href=\"%s\">%s</a></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 = ''
            uri = iurl.absoluteString()
    
            # append html entry for this file
            s += tmpl % (uri, html_escape(iurl.path()), uri, '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
    

     

     

     

    In case, the revised python script is as follows.

     

     

    #!/usr/bin/python
    # coding: utf-8
    # 
    #   file:
    #       qlthumbnail.py
    # 
    #   function:
    #       print html document of hyperlinked thumbnail(s) of given file(s) and put the html data in the clipboard
    # 
    #   usage:
    #       qlthumbnail.py file [file ...]
    # 
    #   version:
    #       0.10a
    #           - added anchor element for path string
    #       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><a href="%s">%s</a></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 = ''
            uri = iurl.absoluteString()
    
            # append html entry for this file
            s += tmpl % (uri, html_escape(iurl.path()), uri, '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()
    

     

     

     

    Good luck,

    H

  • by VikingOSX,

    VikingOSX VikingOSX Sep 15, 2016 11:52 AM in response to kaiuweheinz
    Level 7 (21,014 points)
    Mac OS X
    Sep 15, 2016 11:52 AM in response to kaiuweheinz

    Why are you creating a pandoc folder, and attempting to run that folder as a command in the do shell script? Did you not say that you installed pandoc, and if not, do so as I indicated originally from a package manager (e.g. homebrew). That will put it in /usr/local/bin as an executable program named pandoc.

  • by kaiuweheinz,

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

    Dear VikingOSX and Hiroto,

     

    it works! Both solutions work stably. Thank you sooo much! I had never thought I would once be in the position to choose between two great solutions - yours, VikingOSX and yours, Hiroto.

     

    Considering cons and pros I came to these conclusions:

     

     

       Pros and Cons in Hiroto's solution:

    + linked/clickable thumbnails (no need to include the file path, less space needed)

    + files are selected in finder (habitual show view options + if I need to add another file from the same folder it is still open)

    -  it takes four steps to import the thumbnails into OpenOffice (open out.html in LibreOffice, then save as out.odt, then open out.odt in OpenOffice and copy and paste)

     

       Possible amendment:

    *  have the Script tell the application LibreOffice to open out.html automatically once it has been generated.

    *  replacing file URL by file name as the URL is already contained in the linked thumbnail

      

     

     

     

      Pros and Cons in Hiroto's solution:

    + it takes two steps steps to import the thumbnails into OpenOffice (open work.odt and copy and paste)

    thumbnails are not clickable (file path is needed)

    files are selected within a dialog (no habitual show view options/ going back to the same folder is not possible, dialog always starts with default folder (desktop))


        Possible amendment:

    *  have the Script tell the application OpenOffice to open work.odt automatically once it has been generated.

    *  replacing file URL by file name as the URL is already contained in the linked thumbnail

     

     

     

    Your different solutions show what two brilliant minds like yours are capable of conceiving! I am very much impressed and would wish that the mentioned amendments could perhaps accomplish the great work.

     

    Sincerely,

    Kai-Uwe

  • by kaiuweheinz,

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

    Dear VikingOSX and Hiroto,

     

    it works! Both solutions work stably. Thank you sooo much! I had never thought I would once be in the position to choose between two great solutions - yours, VikingOSX and yours, Hiroto.

     

    Considering cons and pros I came to these conclusions:

     

     

       Pros and Cons in Hiroto's solution:

    + linked/clickable thumbnails (no need to include the file path, less space needed)

    + files are selected in finder (habitual show view options + if I need to add another file from the same folder it is still open)

    -  it takes four steps to import the thumbnails into OpenOffice (open out.html in LibreOffice, then save as out.odt, then open out.odt in OpenOffice and copy and paste)

     

       Possible amendment:

    *  have the Script tell the application LibreOffice to open out.html automatically once it has been generated.

    *  replacing file URL by file name as the URL is already contained in the linked thumbnail

      

     

     

     

      Pros and Cons in Hiroto's solution:

    + it takes two steps steps to import the thumbnails into OpenOffice (open work.odt and copy and paste)

    thumbnails are not clickable (file path is needed)

    files are selected within a dialog (no habitual show view options/ going back to the same folder is not possible, dialog always starts with default folder (desktop))


        Possible amendment:

    *  have the Script tell the application OpenOffice to open work.odt automatically once it has been generated.

    *  replacing file URL by file name as the URL is already contained in the linked thumbnail

     

     

     

    Your different solutions show what two brilliant minds like yours are capable of conceiving! I am very much impressed and would wish that the mentioned amendments could perhaps accomplish the great work.

     

    Sincerely,

    Kai-Uwe

  • by Hiroto,

    Hiroto Hiroto Sep 16, 2016 11:11 AM in response to kaiuweheinz
    Level 5 (7,306 points)
    Sep 16, 2016 11:11 AM in response to kaiuweheinz

    You're quite welcome. Glad to know it worked for you.

     

    Following script implements your suggested amendments - a) to open output html by LibreOffice and b) use file name in lieu of file path in output. I also removed separator (~) for each file in output to make it more compact.

     

    Kind regards,

    Hiroto

     

     

    --APPLESCRIPT
    _main()
    on _main()
        tell application "Finder"
            set aa to selection as alias list
        end tell
        repeat with a in aa
            set a's contents to a's POSIX path
        end repeat
        set out to (path to desktop)'s POSIX path & "out.html"
        create_qlthumbnails_html(aa, out)
        do shell script "open -b org.libreoffice.script " & out's quoted form
    end _main
    
    on create_qlthumbnails_html(argv, out)
        (*
            list argv : list of POSIX path of source files
            string out : POSIX path of output html file
            * this handler puts output html data in the clipboard as well
        *)
        set args to ""
        repeat with a in {} & argv
            set args to args & a's quoted form & space
        end repeat
        do shell script "/usr/bin/python <<'EOF' - " & args & " > " & out's quoted form & "
    # coding: utf-8
    # 
    #   file:
    #       qlthumbnail.py
    # 
    #   function:
    #       print html document of hyperlinked thumbnail(s) of given file(s) and put the html data in the clipboard
    # 
    #   usage:
    #       qlthumbnail.py file [file ...]
    # 
    #   version:
    #       0.10b
    #           - changed path to file name in output
    #           - removed separator (~) for each entry in output
    #       0.10a
    #           - added anchor element for path string
    #       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><a href=\"%s\">%s</a></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 = ''
            uri = iurl.absoluteString()
    
            # append html entry for this file
            s += tmpl % (uri, html_escape(os.path.basename(iurl.path())), uri, '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 create_qlthumbnails_html
    --END OF APPLESCRIPT
    
  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 16, 2016 6:03 PM in response to Hiroto
    Level 1 (8 points)
    Mac OS X
    Sep 16, 2016 6:03 PM in response to Hiroto

    Dear Hiroto,

     

    thank you! That is a thing of beauty! Unfortunately the out.html file opened in LibreOffice cannot be saved as out.odt:

    Bildschirmfoto 2016-09-17 um 02.31.17.png

    So we need to change the Script as following:

    - make Firefox open out.hml (and copy all) and make LibreOffice open a new writer document (and paste clipboard).

    This would allow me to save the LibreOffice and open it in OpenOffice (would that be scriptable too? This would allow me to launch a second script from LibreOffice which would do the rest).

     

    What would be the shortest, most basic script to copy the Quicklook thumbnail of a single file selected in finder to the clipboard in the size 200? (if ever possible with the filename added on top/bottom of the thumbnail as part of the thumbnail)?

     

    If the above mentioned solution (Firefox opens out.html and copies all and LibreOffice opens a new writer document and pastes all) isn't scriptable, I consider making the thumbnails clickable manually as I did in my yesterday's italian lesson's protocol:

    Bildschirmfoto 2016-09-17 um 03.00.10.png

    Even if it was scriptable I'd still be interested for further use in the question: what would be the shortest, simplest, most basic script to retrieve QLthumbnail and copy it to the clipboard. I'll tell you why.

     

     

    With gratitude,

    Kai-Uwe

  • by Hiroto,Helpful

    Hiroto Hiroto Sep 18, 2016 9:43 AM in response to kaiuweheinz
    Level 5 (7,306 points)
    Sep 18, 2016 9:43 AM in response to kaiuweheinz

    Hello

     

    I sort of suspected this because I get a Writer/Web document open by the open command with LibreOffice 4.3.7.2 under OS X 10.6.8 and Writer/Web document seems to be a html document which cannot be saved as ODF text document (.odt). I thought it may have changed with LibreOffice 5 but now I know it didn't.

     

    However, as far as I have tested, I can export the Writer/Web document to .odt via File > Export… menu.

     

    Also, the following script will open the out.html in a LibreOffice Writer document in such a way that I can save it as .odt via File > Save As… menu.

     

     

    --APPLESCRIPT
    _main()
    on _main()
        tell application "Finder"
            set aa to selection as alias list
        end tell
        repeat with a in aa
            set a's contents to a's POSIX path
        end repeat
        set out to (path to desktop)'s POSIX path & "out.html"
        create_qlthumbnails_html(aa, out)
        --do shell script "open -b org.libreoffice.script " & out's quoted form
        do shell script "/Applications/LibreOffice.app/Contents/MacOS/soffice --writer " & out's quoted form & " &>/dev/null &"
    end _main
    
    on create_qlthumbnails_html(argv, out)
        (*
            list argv : list of POSIX path of source files
            string out : POSIX path of output html file
            * this handler puts output html data in the clipboard as well
        *)
        
        -- OMITTED (the same as the previous handler using qlthumbnail.py v0.10b)
        
    end create_qlthumbnails_html
    --APPLESCRIPT
    

     

     

    ----

    As for the thumbnail size, you can change it by changing IMAGE_SIZE value in python script. Currently it is:

     

    IMAGE_SIZE = (512.0, 512.0)
    

     

     

    and changing it to:

     

    IMAGE_SIZE = (200.0, 200.0)
    

     

     

    will yield 200 x 200 pixels thumbnail.

     

     

    ----

    And the following script will put thumbnail jpeg image of the first file in Finder selection in the clipboard. Currently the image size is set to 200 x 200 pixels.

     

     

    --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 & "
    # coding: utf-8
    # 
    #   file:
    #       qlthumbnail_single.py
    # 
    #   function:
    #       create thumbnail of the first file and put image data in the clipboard
    # 
    #   usage:
    #       ./qlthumbnail_single.py file [file ...]
    # 
    #   version:
    #       0.10a
    #           - using -
    #               import Quartz.CoreGraphics as CG
    #               import AppKit as OSX
    #       0.10
    #           - draft
    # 
    import sys, os, objc
    import Quartz.CoreGraphics as CG    # required for QLThumbnailImageCreate() using CG symbols
    import AppKit as OSX
    
    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 main():
        data = None
        for f in [ a.decode('utf-8') for a in sys.argv[1:2] ]:  # process the first file only
            iurl = OSX.NSURL.fileURLWithPath_(f)
            cgi = QLThumbnailImageCreate(
                OSX.kCFAllocatorDefault,
                iurl,
                CG.CGSizeMake(*IMAGE_SIZE),
                { kQLThumbnailOptionIconModeKey : OSX.kCFBooleanTrue }
            )
            if cgi:
                brep = OSX.NSBitmapImageRep.alloc().initWithCGImage_(cgi)
            else:
                icon = OSX.NSWorkspace.sharedWorkspace().iconForFile_(iurl.path())
                brep = OSX.NSBitmapImageRep.imageRepWithData_(icon.TIFFRepresentation())
                brep.setSize_(OSX.NSMakeSize(*IMAGE_SIZE))
            data = brep.representationUsingType_properties_(OSX.NSJPEGFileType, {})
    
        if data:
            # put jpeg data in clipboard
            pboard = OSX.NSPasteboard.generalPasteboard()
            pbtype = 'public.jpeg'
            pboard.declareTypes_owner_([pbtype], None)
            pboard.setData_forType_(data, pbtype)
    
    IMAGE_SIZE = (200.0, 200.0)
    main()
    EOF"
    --END OF APPLESCRIPT
    

     

     

    Good luck,

    H

  • by VikingOSX,

    VikingOSX VikingOSX Sep 17, 2016 11:12 AM in response to kaiuweheinz
    Level 7 (21,014 points)
    Mac OS X
    Sep 17, 2016 11:12 AM in response to kaiuweheinz

    Here is a version 2.0 of my AppleScript. It generates an HTML5 web page that has horizontally aligned, and wrapped 200 px, hyperlinked thumbnails. As you hover over a given thumbnail, the base filename is displayed. The output appears identical in Safari 9.1.3 and Firefox 48.0.1. A single-click on a thumbnail will either launch that document in its default application, or the Finder with the original document selected.

     

    To achieve this added functionality, I have moved to markdown from LaTeX in the metafile, and now also generate custom CSS to help pandoc override the default vertical thumbnail layout in the HTML.

     

    In the header comments of the AppleScript, I have illustrated how to use the LibreOffice command-line tool to transform the HTML5 page into either ODT, or DOCX. This process preserves the hyperlinked thumbnails in the target document. The thumbnails are minimalized, so one must right-click on each, and from the properties : crop panel, click original size and OK. One can also make a multicolumn document from the Format : Page... panel.

     

    I don't believe I have any more to contribute, and have to refocus on other demands now. Viel Glück!

     

    Some images:

     

    Safari 9.1.3 (same appearance in Firefox 48.0.1)

    Screen Shot 2016-09-17 at 12.17.44 PM.jpg

    LibreOffice 5.2.1.2: (.odt shown)

    Screen Shot 2016-09-17 at 2.10.10 PM.jpg

    AppleScript

     

    -- ql_link.applescript

    -- Writes custom.css, and markdown files. The latter contains content

    -- that enables hyperlinked thumbnails with hover filenames.

    -- When processing is complete, the third-party pandoc (pandoc.org) application is used

    -- to convert markdown content to an HTML5 web page.

    --

    -- Optional: use the LibreOffice command-line tool soffice to convert the

    -- HTML5 content to either ODT, or DOCX documents. This will preserve

    -- all HTML functionality including hyperlinks on thumbnails and hover text

    -- The following commands have wrapped, it is a single-line invocation. Output work.odt, or work.docx.

    --

    -- /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to odt --outdir ~/Desktop work.html

    -- /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to docx:"MS Word 2007 XML" --outdir ~/Desktop work.html

    --

    -- Version 2.0. • Rewrite. Switched from LaTeX to markdown metadata for improved f(x).

    --                   • Include custom CSS to assist pandoc generation of horizontal html5 content.

    --                   • allows horizontal 200 px thumbnails that wrap on web page.

    --                   • A single-click on a thumbnail in Safari 9.1.3 will open

    --                     that document in its default application, or Finder window.

    -- VikingOSX, Sept 17, 2016, Apple Support Communities

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

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

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

    property mfile : POSIX path of metafile

    property cssfile : (path to desktop as Unicode text) & "custom.css"

    property cfile : POSIX path of cssfile

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

    property fileCnt : missing value

     

    use scripting additions

     

    tell application "Finder"

      if exists file metafile then

      delete file metafile

      end if

      if exists file cssfile then

      delete file cssfile

      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

     

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

     

    -- create new cssfile and initialize it

    set fcRef to openFileHandle(cssfile, true)

    init_cssfile(fcRef)

     

    set fRef to openFileHandle(metafile, true)

    if fRef is false then return

     

    set fileCnt to (count of inPath)

    repeat with afile in inPath

      tell application "Finder"

      set ImgPath to ""

      set theURL to (afile's URL) as «class utf8»

      set theName to (afile's name) as «class utf8»

      -- because qlmanager generates name.extension.png image names!!

      set ImgPath to POSIX path of (thumbpath & theName & ".png") as «class utf8»

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

      end tell

     

      try

      -- use the QuickLook manager to generate a 200 pixel icon. Better to downsample.

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

      tell application "Finder" to set imgURL to URL of (POSIX file ImgPath as alias)

      log imgURL

      write_metadata(fRef, theURL, theName, imgURL)

      on error errmsg number errnbr

      my error_handler(errnbr, errmsg)

      close access the fRef

      return

      end try

    end repeat

    close access the fRef

    do shell script "/usr/local/bin/pandoc -s -H " & cfile & " -f markdown -t html5 -o ~/Desktop/work.html " & mfile

    do shell script "open ~/Desktop/work.html"

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

    set fileCnt to (0 as integer)

    return

     

    on openFileHandle(filePath, overwrite)

      try

      set the filePath to the filePath as Unicode text

      set the fp to open for access file filePath with write permission

      if overwrite is true then set eof of the fp to 0 -- truncate file

      on error errmsg number errnbr

      try

      close access the fp

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

      if overwrite is true then set eof of fp to 0

      on error

      my error_handler(errnbr, errmsg)

      return false

      end try

      end try

     

      return fp

     

    end openFileHandle

     

    on init_cssfile(fh)

      -- Override the pandoc generated HTML5

      -- this CSS will be provided to pandoc on its command-line with the -H flag

      set eof of fh to 0

      write "<!-- force thumbnails to appear in horizontal layout in HTML -->" & ¬

      linefeed as «class utf8» to fh starting at eof

      write "<style type=\"text/css\">" & linefeed as «class utf8» to fh starting at eof

      write "img {display:inline-block;margin:5px 20px;padding:5px;}" & linefeed as «class utf8» ¬

      to fh starting at eof

      write " p {display:inline;margin:0;padding:0;}" & linefeed as «class utf8» ¬

      to fh starting at eof

      write "</style>" as «class utf8» to fh starting at eof

      close access fh

      return

    end init_cssfile

     

    on write_metadata(fh, aURL, aName, theImgURL)

     

      -- markdown syntax to make hyperlinked thumbnails

      write "[![](" & theImgURL & space & "\"" & aName & "\")](" & aURL & ")" & ¬

      linefeed & linefeed to fh starting at eof as «class utf8»

      return

     

    end write_metadata

     

    on error_handler(nbr, msg)

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

    end error_handler

    o

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 18, 2016 4:17 AM in response to Hiroto
    Level 1 (8 points)
    Mac OS X
    Sep 18, 2016 4:17 AM in response to Hiroto

    Dear Hiroto,

     

    thank you for your sleek scripts that serve me for many occasions. I could implement your last one into my Script that allows me to copy the fileURL to the clipboard. Thanks to CopyPaste Pro I could first paste the thumbnail into the document and second the fileURL into the thumbnail's context menu 'hyperlink' creating thus in few time a linked thumbnail.

     

    Thank you for all your effort, good luck or rather shalom which includes luck, health, financial provision and everything pertaining to a happy life May God reward you richly for the time you invested! Kai 

  • by kaiuweheinz,

    kaiuweheinz kaiuweheinz Sep 18, 2016 4:59 AM in response to VikingOSX
    Level 1 (8 points)
    Mac OS X
    Sep 18, 2016 4:59 AM in response to VikingOSX

    Dear VikingOSX,

     

    thank you for your master piece which allows me to open it directly in OpenOffice! I could put Hiroto's script at the end which automatically opens work.odt in OpenOffice and there I can change the order, duplicate the linked thumbnails - which even with linked thumbnails that were genuinely created in OpenOffic wasn't possible! Because each time I copied them and pasted them elsewhere in the document the link was gone. Even in LibreOffice. Not with your genial script that will solve my question and close the case - except for one last thing, and I am well aware of the fact a man of your format must move on:

    As you can see ...

    Bildschirmfoto 2016-09-18 um 01.00.30.png

    ... the linked thumbnails, once copied in my protocol contain 2 comments (which each I must delete manually). Now I managed to eliminate the latter by eliminating the lines

     

      write "<!-- force thumbnails to appear in horizontal layout in HTML -->" & ¬

      linefeed as «class utf8» to fh starting at eof

     

    o

    o

    so I only need to delete the first comment but I tried all lines and still couldn't eliminate the first one without harming the Script's functioning. What I discerned was that the comments always occurr after the first thumbnail. So I came up with one last request: could you have the script double the first selected file? Then I could just copy the second to last thumbnail, paste them in my protocol and close work.html without extra time for deleting. And - if ever you are still willing to take a last look on that: couldn't you have the script start at the moment where the files are already selected? Selecting them in the dialog is not as practical as selecting them in the finder where I can move with much more ease. And: is there a possibility to eliminate the borders (that appear both in LibreOffice and in OpenOffice and which of course can be toggled off manually yet what I wouldn't do for reasons of efficiency )?

     

    But do this, dear VikingOSX, only I you can afford one last thought on this question. If not, let me know and I will close the post by clicking "This solved my question" below your last post.

     

    I thank you deep-heartedly for investing so much time and as I wrote to Hiroto too I wish you not only "Viel Glück" but shalom, the blessing from above, given the fact that shalom includes Glück , peace, blessings in health, finances and relationships, which works only because someone has paid the price, so one should translate it with 'happiness all around' - that comes with trusting in His son.

     

    Thank you guys, you revolutionized, my high school teaching and a dream I have been cherishing for about a year has come true.

     

    Kind regards,

    Kai-Uwe

  • by VikingOSX,Solvedanswer

    VikingOSX VikingOSX Sep 18, 2016 9:43 AM in response to kaiuweheinz
    Level 7 (21,014 points)
    Mac OS X
    Sep 18, 2016 9:43 AM in response to kaiuweheinz

    Here is version 2.1 of my previous script. I does the following:

    1. Eliminates the choose file prompt. You now select the files to process in the Finder, and then run the script.
    2. All comments are gone from the HTML and inherently, the ODT documents.
      1. Removed custom.css comment
      2. Changed the pandoc output from HTML5 to HTML
        1. Now excludes the conditional comment for Internet Explorer 9 compatibility
        2. Now excludes the html5shiv JavaScript link
    3. Cannot fix thumbnail outline in LibreOffice
      1. LibreOffice issue, not script production, or controllable factor.
      2. Thumbnail outline persists after manually disabling border outline property for the image.

    AppleScript

     

    -- ql_link.applescript

    -- Writes custom.css, and markdown files. The latter contains content

    -- that enables hyperlinked thumbnails with hover filenames shown.

    -- When processing is complete, the third-party pandoc (pandoc.org) application is used

    -- to convert markdown content to an HTML web page.

    --

    -- Optional: use the LibreOffice command-line tool soffice to convert the

    -- HTML content to either ODT, or DOCX documents. This will preserve

    -- all HTML functionality including hyperlinks on thumbnails and hover text

    -- The following commands have wrapped, it is a single-line invocation. Output work.odt, or work.docx.

    --

    -- /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to odt --outdir ~/Desktop work.html

    -- /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to docx:"MS Word 2007 XML" --outdir ~/Desktop work.html

    --

    -- Version 2.1. • Rewrite. Switched from LaTeX to markdown metadata for improved f(x).

    --                     • Include custom CSS to assist pandoc generation of horizontal html content.

    --                     • allows horizontal 200 px thumbnails that wrap on web page.

    --                     • A single-click on a thumbnail in Safari 9.1.3 (or Firefox 48.0.1) will open

    --                       that document in its default application, or Finder window.

    --                     • Replaced choose file with Finder selection(s)

    --                     • All comments now suppressed in html and odt documents.

    -- VikingOSX, Sept 18, 2016, Apple Support Communities

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

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

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

    property mfile : POSIX path of metafile

    property cssfile : (path to desktop as Unicode text) & "custom.css"

    property cfile : POSIX path of cssfile

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

    property fileCnt : missing value

     

    use scripting additions

     

    tell application "Finder"

      if exists file metafile then

      delete file metafile

      end if

      if exists file cssfile then

      delete file cssfile

      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

     

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

    -- Finder selected documents are made into a file list

    tell application "Finder"

      set inPath to the selection as alias list

    end tell

     

    -- create new cssfile and initialize it

    set fcRef to openFileHandle(cssfile, true)

    init_cssfile(fcRef)

     

    set fRef to openFileHandle(metafile, true)

    if fRef is false then return

     

    set fileCnt to (count of inPath)

    repeat with afile in inPath

      tell application "Finder"

      set ImgPath to ""

      set theURL to (afile's URL) as «class utf8»

      set theName to (afile's name) as «class utf8»

      -- because qlmanager generates name.extension.png image names!!

      set ImgPath to POSIX path of (thumbpath & theName & ".png") as «class utf8»

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

      end tell

     

      try

      -- use the QuickLook manager to generate a 200 pixel icon. Better to downsample.

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

      tell application "Finder" to set imgURL to URL of (POSIX file ImgPath as alias)

      log imgURL

      write_metadata(fRef, theURL, theName, imgURL)

      on error errmsg number errnbr

      my error_handler(errnbr, errmsg)

      close access the fRef

      return

      end try

    end repeat

    close access the fRef

    do shell script "/usr/local/bin/pandoc -H " & cfile & " -f markdown -t html -o ~/Desktop/work.html " & mfile

    do shell script "open ~/Desktop/work.html"

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

    set fileCnt to (0 as integer)

    return

     

    on openFileHandle(filePath, overwrite)

      try

      set the filePath to the filePath as Unicode text

      set the fp to open for access file filePath with write permission

      if overwrite is true then set eof of the fp to 0 -- truncate file

      on error errmsg number errnbr

      try

      close access the fp

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

      if overwrite is true then set eof of fp to 0

      on error

      my error_handler(errnbr, errmsg)

      return false

      end try

      end try

     

      return fp

     

    end openFileHandle

     

    on init_cssfile(fh)

      -- Override the pandoc generated HTML

      -- this CSS will be provided to pandoc on its command-line with the -H flag

      set eof of fh to 0

      write "<style type=\"text/css\">" & linefeed as «class utf8» to fh starting at eof

      write "img {display:inline-block;margin:5px 20px;padding:5px;}" & linefeed as «class utf8» ¬

      to fh starting at eof

      write " p {display:inline;margin:0;padding:0;}" & linefeed as «class utf8» ¬

      to fh starting at eof

      write "</style>" as «class utf8» to fh starting at eof

      close access fh

      return

    end init_cssfile

     

    on write_metadata(fh, aURL, aName, theImgURL)

     

      -- markdown syntax to make hyperlinked thumbnails

      write "[![](" & theImgURL & space & "\"" & aName & "\")](" & aURL & ")" & ¬

      linefeed & linefeed to fh starting at eof as «class utf8»

      return

     

    end write_metadata

     

    on error_handler(nbr, msg)

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

    end error_handler

    op

  • by kaiuweheinz,

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

    Thank you so much!!

first Previous Page 3 of 4 last Next