[OS X TeX] A Pair of TeXShop Applescript Macros

Norm Gall gall at spookyhill.net
Tue Apr 26 15:33:57 CEST 2005


Since Carbon Emacs is broken on Tiger for the time being, I have  
returned ot good ol' TeXShop.

However, I like light characters on dark backgrounds and ever so  
slightly transparent windows. The {rgb} number system is terrible to  
use with the default write method of setting preferences, so I wrote  
these two applescripts for TeXShop.

Open up the Macro Editor and stick 'em in.

I have only two complaints: a) I cannot figure out how to get  
ScriptRunner to come to the front and b) the cursor and caret do not  
seem to have any defaults settings. They are essentially invisible  
with a very dark background.

Enjoy.  If you have suggestions, please e-mail.

-- Applescript to set the editor colours

-- This script reads the current TeXShop defaults and displays them
-- in the colour picker you see. If you want what you have, just
-- hit ok.

-- copyleft 2005 Norm Gall <gall at spookyhill.net>

display dialog "The current colours are pre-set for each picker. To  
accept the current setting, just press Ok for the picker." buttons  
"Ok" default button 1

-- do background colour

display dialog "Choose a background colour" buttons "Next" default  
button 1

set red to do shell script "defaults read TeXShop background_R"
set green to do shell script "defaults read TeXShop background_G"
set blue to do shell script "defaults read TeXShop background_B"

myPicker(red, green, blue)
set foo to the result

do shell script "defaults write TeXShop background_R " & item 1 of foo
do shell script "defaults write TeXShop background_G " & item 2 of foo
do shell script "defaults write TeXShop background_B " & item 3 of foo

-- do foreground colour

display dialog "Choose a foreground colour" buttons "Next" default  
button 1

set red to do shell script "defaults read TeXShop foreground_R"
set green to do shell script "defaults read TeXShop foreground_G"
set blue to do shell script "defaults read TeXShop foreground_B"

myPicker(red, green, blue)
set foo to the result

do shell script "defaults write TeXShop foreground_R " & item 1 of foo
do shell script "defaults write TeXShop foreground_G " & item 2 of foo
do shell script "defaults write TeXShop foreground_B " & item 3 of foo

-- do comment colour

display dialog "Choose a comment text colour" buttons "Next" default  
button 1

set red to do shell script "defaults read TeXShop commentred"
set green to do shell script "defaults read TeXShop commentgreen"
set blue to do shell script "defaults read TeXShop commentblue"

myPicker(red, green, blue)
set foo to the result

do shell script "defaults write TeXShop commentred " & item 1 of foo
do shell script "defaults write TeXShop commentgreen " & item 2 of foo
do shell script "defaults write TeXShop commentblue " & item 3 of foo

-- do command colour

display dialog "Choose a LaTeX command text colour" buttons "Next"  
default button 1

set red to do shell script "defaults read TeXShop commandred"
set green to do shell script "defaults read TeXShop commandgreen"
set blue to do shell script "defaults read TeXShop commandblue"

myPicker(red, green, blue)
set foo to the result

do shell script "defaults write TeXShop commandred " & item 1 of foo
do shell script "defaults write TeXShop commandgreen " & item 2 of foo
do shell script "defaults write TeXShop commandblue " & item 3 of foo

-- set marker colour

display dialog "Choose a LaTeX marker text colour" buttons "Next"  
default button 1

set red to do shell script "defaults read TeXShop markerred"
set green to do shell script "defaults read TeXShop markergreen"
set blue to do shell script "defaults read TeXShop markerblue"

myPicker(red, green, blue)
set foo to the result

do shell script "defaults write TeXShop markerred " & item 1 of foo
do shell script "defaults write TeXShop markergreen " & item 2 of foo
do shell script "defaults write TeXShop markerblue " & item 3 of foo

-- warn user

display dialog ¬
     "You must quit and re-launch TeXShop to see the effects of your  
changes" buttons "Ok" default button 1

-- get a picker
on myPicker(rValue, gValue, bValue)

     set rValue to rValue as real
     set gValue to gValue as real
     set bValue to bValue as real

     set rValue to rValue * 65535 as integer
     set gValue to gValue * 65535 as integer
     set bValue to bValue * 65535 as integer

     set rgbValue to ¬
         choose color default color {rValue, gValue, bValue}
     set rValue to (item 1 of rgbValue) / 65535
     set gValue to (item 2 of rgbValue) / 65535
     set bValue to (item 3 of rgbValue) / 65535

     set rgbValue to rValue & gValue & bValue
     return rgbValue

end myPicker



-- Applescript to set window transparency

--  Created by Norman Gall on 26/04/05.
--  Copyleft 2005 Spookyhill. All rights reserved.

-- do source window

set alpha to do shell script "defaults read TeXShop SourceWindowAlpha"

set the Reply to display dialog "Set transparency of source window:
(value between 0 and 1):" default answer alpha buttons {"Cancel",  
"Ok"} default button "Ok"

set alpha to text returned of the result as real

if alpha is greater than or equal to 0 and alpha is less than or  
equal to 1 then
     do shell script "defaults write TeXShop SourceWindowAlpha " & alpha
else
     display dialog "Value must be between 0 and 1" buttons "ok"  
default button 1
end if

-- do preview window

set alpha to do shell script "defaults read TeXShop PreviewWindowAlpha"

set the Reply to display dialog "Set transparency of preview window:
(value between 0 and 1):" default answer alpha buttons {"Cancel",  
"Ok"} default button "Ok"

set alpha to text returned of the result as real

if alpha is greater than or equal to 0 and alpha is less than or  
equal to 1 then
     do shell script "defaults write TeXShop PreviewWindowAlpha " &  
alpha
else
     display dialog "Value must be between 0 and 1" buttons "ok"  
default button 1
end if

-- do console

set alpha to do shell script "defaults read TeXShop ConsoleWindowAlpha"

set the Reply to display dialog "Set transparency of console window:
(value between 0 and 1):" default answer alpha buttons {"Cancel",  
"Ok"} default button "Ok"

set alpha to text returned of the result as real

if alpha is greater than or equal to 0 and alpha is less than or  
equal to 1 then
     do shell script "defaults write TeXShop ConsoleWindowAlpha " &  
alpha
else
     display dialog "Value must be between 0 and 1" buttons "ok"  
default button 1
end if

-- warn user

display dialog ¬
     "You must quit and re-launch TeXShop to see the effects of your  
changes" buttons "Ok" default button 1


-- 
"The Americans  will always do the right thing... After they've  
exhausted
  all the  alternatives."                              - Winston  
Churchill

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the macostex-archives mailing list