[OS X TeX] Applescript to help update the Engines folder after a TeXShop update

Ramón Figueroa-Centeno ramonf at hawaii.edu
Thu Feb 25 07:44:33 CET 2010


Aloha,

Below is an applescript to help integrate new engines after a TeXShop
update. Options settable in the beginning of it. 

Now, if you are like me and don't want an extra copy of an active engine
that really has not changed (MD5 sum and name are the same) in the Inactive
folder then set "trashdups" to true, and they will be trashed (not deleted).
Otherwise set it to false and they the duplicates will be labeled red in the
Finder.

Moreover, if you wish to replace old engines with new ones (same name but
different MD5 sum), set "update" to true. Otherwise set it to false and have
the old ones labeled orange and the new ones green. Now, here "old" and
"new" can be relative terms, in the case that you, for example, have
modified an engine and do not wish it to be "updated", then the old is new
and the new is old. For that there is an ignore list, where you can place
the names of the engines that you wish to be left alone (Herb Schultz, I
believe, mentioned in another posting that he, for example, modifies the
default engines at times, and would not like them to be "updated").

I suggest you try the script out first with both "trashdups" and "update"
set to false and make a backup of the Engines folder, until we know it is
really safe (no bugs or wrong assumptions). It works for me, but no
guarantees.

To use it copy and paste it from below into a new document in the "Script
Editor". If you find it useful you can save it as a standalone application
(or as a TeXShop Macro, I guess, but I have not tried it that way).

Enjoy!

Ramón

------

-- Script to help organize new engines after a TeXShop update.
-- Ramon Figueroa-Centeno (February 24, 2010)

-- Trash duplicate (already installed) engines in the Inactive folder or
just label them red
property trashdups : false
-- Replace "old" engines with "new" ones in the Inactive folder or just
label the "old" ones orange
-- (the new ones always get green).
property update : false
-- A list of the engines that you wish to "NOT" be trashed, e.g., "XeLaTeX"
(not "XeLaTeX.engine").
-- The names are case sensitive!
property ignore_list : {}

-- Find all the engines in "/Library/TeXShop/Engines" (or subdirectories
thereof) and compute their md5sum
set command to "find ~/Library/TeXShop/Engines -name '*.engine' -type f
-exec md5sum {} \\;"
set candidates to paragraphs of (do shell script command)
set engines to {}
set md5sums to {}
set names to {}
repeat with p in candidates
	set md5sums to md5sums & {(characters 1 thru 32 of p) as string}
	set filepath to (characters 36 thru -1 of p) as string
	set engines to engines & {filepath}
	set basename to do shell script "basename " & quoted form of filepath & "
.engine"
	set names to names & {basename}
end repeat

-- Assume that there are at most two of each engine, one active and/or one
inactive.
-- When there are two engines define the one in the Inactive folder as "new"
and the other as old"

set duplicates to {}
set new_engines to {}
set old_engines to {}
repeat with i from 1 to (count of engines) - 1
	repeat with j from i + 1 to count of engines
		if (item i of names) = (item j of names) then
			set e1 to item i of engines
			set e2 to item j of engines
			if (item i of md5sums) = (item j of md5sums) then
				if e1 contains "Inactive" and e2 does not contain "Inactive" then
					set duplicates to duplicates & {e1}
				else if e2 contains "Inactive" and e1 does not contain "Inactive" then
					set duplicates to duplicates & {e2}
				end if
			else
				if e1 contains "Inactive" and e2 does not contain "Inactive" then
					set new_engines to new_engines & {e1}
					set old_engines to old_engines & {e2}
				else if e2 contains "Inactive" and e1 does not contain "Inactive" then
					set new_engines to new_engines & {e2}
					set old_engines to old_engines & {e1}
				end if
			end if
		end if
	end repeat
end repeat

-- Finder labels
property nolabel : 0
property red : 2
property orange : 1
property yellow : 3
property green : 6
property blue : 4
property purple : 5
property gray : 7

tell application "Finder" to activate

-- unlabel all the engines in the folder Engines hierarchy
repeat with f in engines
	set f to POSIX file f
	tell application "Finder"
		if the label index of file f is not in {nolabel, green} then
			set the label index of file f to nolabel
		end if
	end tell
end repeat

-- label or trash duplicates
repeat with f in duplicates
	set fname to do shell script "basename " & quoted form of f & " .engine"
	set f to POSIX file f
	if trashdups and (fname is not in ignore_list) then
		--trash the inactive duplicate if it is not in the ignore list
		tell application "Finder" to move the file f to the trash
	else
		tell application "Finder" to set the label index of file f to red
	end if
end repeat

-- label or trash "old" engines
repeat with f in old_engines
	set fname to do shell script "basename " & quoted form of f & " .engine"
	set f to POSIX file f
	if update and (fname is not in ignore_list) then
		--trash old engine if it is not the ignore list
		tell application "Finder" to move the file f to the trash
	else
		tell application "Finder" to set the label index of file f to orange
	end if
end repeat

-- label or activate "new" engines
repeat with f in new_engines
	set fname to do shell script "basename " & quoted form of f & " .engine"
	set f to POSIX file f
	tell application "Finder" to set the label index of file f to green
	if update and (fname is not in ignore_list) then
		--activate new engine  if the "old" one is not the ignore list
		tell application "Finder"
			move the file f to the folder "Engines" of the folder "TeXShop" of the
folder "Library" of home without replacing
		end tell
	end if
end repeat

-- 
View this message in context: http://n2.nabble.com/Applescript-to-help-update-the-Engines-folder-after-a-TeXShop-update-tp4630928p4630928.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.



More information about the macostex-archives mailing list