[OS X TeX] Re: Applescript to help update the Engines folder after a TeXShop update
Ramón Figueroa-Centeno
ramonf at hawaii.edu
Fri Feb 26 19:03:46 CET 2010
Aloha,
I revised the script to add user interaction.
Enjoy!
Ramón
------
-- Script to help organize new engines after a TeXShop update.
-- Ramon Figueroa-Centeno (February 24, 2010)
-- History:
-- Version 1.1: Add user interaction
-- 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 names to names & {nameof(filepath)}
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
set howmany to (count of duplicates) + (count of old_engines)
if howmany > 0 then
display dialog (howmany as string) & " Eponymous were engines found. \rDo
you wish me to process them?\r (Every engine's Finder label is reset)" with
icon 0
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} then
set the label index of file f to nolabel
end if
end tell
end repeat
else
return
end if
if duplicates is not {} then
display dialog "Do you want to delete or label red your inactive duplicate
engines?" buttons {"Cancel", "Delete", "Label Red"} default button "Label
Red"
set answer to button returned of the result
if answer is "Label Red" then
set trashdups to false
else if answer is "Delete" then
set trashdups to true
else
return
end if
set names to sort(getnames(duplicates))
set names to choose from list names with prompt "Choose Engines:\rTip:
Press ⌘ key and click items" with title "Duplicates" default items names
with multiple selections allowed and empty selection allowed
if result is false then return
end if
-- label or trash duplicates
repeat with f in duplicates
set fname to nameof(f)
set f to POSIX file f
if (fname is not in ignore_list) and (fname is in names) then
if trashdups 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 if
end repeat
if old_engines is not {} then
display dialog "Do you want to \"update\" or label your \"old\" and \"new\"
engines?" buttons {"Cancel", "Update", "Label"} default button "Label"
set answer to button returned of the result
if answer is "Label" then
set update to false
else if answer is "Update" then
set update to true
else
return
end if
set names to sort(getnames(old_engines))
set names to choose from list names with prompt "Choose Engines:\rTip:
Press ⌘ key and click items" with title "\"Updated\" Engines" default items
names with multiple selections allowed and empty selection allowed
if result is false then return
end if
-- label or trash "old" engines
repeat with f in old_engines
set fname to nameof(f)
set f to POSIX file f
if (fname is not in ignore_list) and (fname is in names) then
if update 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 if
end repeat
-- label or activate "new" engines
repeat with f in new_engines
set fname to nameof(f)
set f to POSIX file f
if (fname is not in ignore_list) and (fname is in names) then
tell application "Finder" to set the label index of file f to green
if update 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 if
end repeat
on getnames(the_list)
set new_list to {}
repeat with f in the_list
set fname to nameof(f)
--set fname to do shell script "basename " & quoted form of f & " .engine"
set new_list to new_list & {fname}
end repeat
return new_list
end getnames
on nameof(f)
set fname to do shell script "basename " & quoted form of f & " .engine"
return fname
end nameof
(*
http://www.macosxhints.com/article.php?story=20040513173003941
Sort lists in AppleScript using the Unix sort command
Mon, May 17 '04 at 09:13AM • from: erickaterman *)
on sort(the_list)
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- always a
linefeed
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & "
| sort -f -u"
set new_list to (paragraphs of new_string)
set AppleScript's text item delimiters to old_delims
return new_list
end sort
--
View this message in context: http://n2.nabble.com/Applescript-to-help-update-the-Engines-folder-after-a-TeXShop-update-tp4630928p4640774.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.
More information about the macostex-archives
mailing list