SuperCard Shell Essentials

 

Image to html

Page history last edited by DCS 3 yrs ago

Image to html

preview icns files in html

The following script creates png files from icns files using sips and produces an html file which is automatically opened by the user's default web browser.

Converted images are stored in an invisible folder which is purged before each search.

 

Notes:

Converted images should be retained and filtered to increase speed of subsequent searches.

Html does not include header or footer. It should, but works with Safari as is.

Initial conversion from path to path + tab + destination name may be further simplified as sips automatically renames converted file.

 

on mouseUp
ask "enter regular expression"
put it into grepStr
--prompt user for a character string and set a SC variable
--string can be any valid extended regular expression
set the idlecontrols to true
set the style of me to chasingarrows
--set button type indicate busy (not functional, fix if possible)
put projectpath(this proj) into d
--set SC var to project path
put ".~pngStore" into d2
--set a SC variable to the name of folder to create to store converted images
--leading dot will make the folder invisible
put "`" into bq
--set a SC var to backquote (shell command expansion metacharacter)
--protect from merge
put "cd `[[bq]]osascript -e 'posix path of alias `[[d]]`' | perl -pe chomp[[bq]]` " into cmd
--set working directory to project folder
put "; rm -dr [[d2]] " after cmd
--remove the image store folder and it's content (if it exists)
--throws an error to console, should be handled differently
put " ; mkdir [[d2]] " after cmd
--make image store folder
put " ; cd ./[[d2]]  " after cmd
--change working directory to image store folder
put " ; pwd " after cmd
--return current working directory as an error check
put " ;locate '*.icns' | grep -iEv '^/volumes/' " after cmd
--use locate to return paths to all icns files
--strip non boot volumes via grep
put " | grep -iE '[[grepstr]]' " after cmd
--trim paths to those matching the user input regular expression
put " | awk -v dq='`' '{printf $0 `t` NR `_` ; system(`basename ` dq$0dq)}' " after cmd
--use awk to convert each line containing a path into tab delimited data
--where column 1 is the full unix path 
--and column 2 is a serial number + underscore + the icns file name
put " | perl -pe 's/.icns$/.png/' " after cmd
--change column 2 file name extension from .icns to .png
put " | awk -Ft -v dq='`' '{system(`sips -s format png ` dq$1dq` --out `dq$2dq)}' > ~ndx.txt 2>&1  " after cmd
--use awk execute sips conversion from icns file to png
--sips result messages are saved to a file '~ndx.txt' which will be converted to html
--each line of input is returned as two lines if no error
--1st line: the source path
--2nd line: a slash + name of converted file
put " ; grep -E '^Error|^Try |^Warning |^libpng error' < ~ndx.txt  > ~errors.txt  " after cmd
--read '~ndx.txt' and save lines containing error strings to an errors file
put " ; grep -Ev '^Error|^Try |^Warning |^libpng error' < ~ndx.txt  > ~ndx.txt~  " after cmd
--read '~ndx.txt' and save lines whithout error strings to a new file
put " ; tr `n` `r` < ~ndx.txt~ > ~ndx.txt " after cmd
--read 'ndx' file, change linefeeds to carriage returns and resave
put " ; rm -f ~ndx.txt~  " after cmd
--remove temporary file
put " ; perl -pi -e 's/r  //t//g' ~ndx.txt " after cmd
--replace every occurrence of <carriage return><space><slash> to <tab><slash>
put " ; perl -pi -e 's/r/n/g' ~ndx.txt " after cmd
--replace every carriage return with a linefeed
--now each line consists of 2 columns again
--source path <tab><slash>converted file name
put " ; perl -pi -e 's/t.*[[d2]](.*)$/t[[d2]]$1/' ~ndx.txt " after cmd
--use perl to prepend the image store folder name to 2nd column
put " ; perl -pi -e 's/([^0-9a-zt/n])/`%` . unpack(`H2`,$1)/gie' ~ndx.txt "  after cmd
--use perl to html encode non alpha numeric characters in each line of data
--excluding linefeeds, slashes, and tabs
put " ; perl -pi -e 's/^(.+)t(.+)$/<a href=x22file://$1x22><img src=x22$2x22></a>/' ~ndx.txt " after cmd
--use perl to prepend each line with 'a href=' + a double quote
--replace each tab with a double quote + '><img src=' + double quote
--append each line with a double quote + '></a>'
put " ; mv ~ndx.txt ../index.html " after cmd
--move the 'ndx' file to same level as project and rename to 'index.html'
--should wrap in a html header & footer, but works like this with safari.
put " ; open ../index.html " after cmd
--open the html file with the application specified by directory services
put merge(cmd) into cmd
--merge command syntax
get shell(cmd)
--execute
set the style of me to roundrect
-reset button style
end mouseUp

Comments (0)

You don't have permission to comment on this page.