Friday, March 2, 2012

Move the /Developer folder to an external usb/firewire harddrive or another partition

The installer for Xcode 4 does not allow you to switch the install locations if you just run the installer downloaded from the App Store. When it finishes installing, a directory called Developer will have been created the root of the harddrive. I own a Macbook Air with limited flash space. The developer directory is a pig and I don't really use it much on my laptop, but I wanted to install a few unix utilities from MacPorts. Here is how you do it:

Step 1: I used rsync to move the /Developer folder to my external usb harddrive. You might be able to copy it without rsync, but I used rsync + option "-a" for getting the permissions copied.
sudo rsync -az --progress /Developer /Volumes/USBDRIVE/

Step 2: I then created a symbolic link to the new folder on the usb drive.
sudo ln -s /Volumes/USBDRIVE/Developer /Developer

Step 3 (optional for MacPorts): Edit your macports.conf to include the new location of xcode. I used TextWrangler because it can handle the root access to edit the file. You could also use nano. Look for this line "developer_dir Developer/Applications/Xcode.app/Contents/Developer" and change the path to your path.
sudo open -a TextWrangler /opt/local/etc/macports/macports.conf
OR
sudo nano /opt/local/etc/macports/macports.conf

ALL DONE!!!

Wednesday, February 29, 2012

Nifty Box - Add Finder Color Label to Untagged Files in Particular Folder AppleScript

This script will let you pick a color and a folder to scan. It will not color folders, just files. Its helpful in finding unneeded files. You can add a tag to important files and remove those files which are not needed.


--color selection
set theColors to {"blank", "orange", "red", "yellow", "blue", "purple", "green", "gray"}

set myColor to (choose from list theColors)
if (myColor is false) then error number -128
set myColor to item 1 of myColor

--this part finds out what theIndex (number) the label is.
set a to 1
repeat until ((item a of theColors) is myColor)
set a to (a + 1)
end repeat
set theIndex to a - 1


-- Or, in this case, simply:
-- tell application "Finder" to set label index of entire contents of mainFolder to theIndex






-----------------------end of color selection code
--i get the desired nifty box tagged items--ouput is posix path names in list "taggedList"
tell application "Nifty Box"
set tagged_items to nbitems
set taggedPosix to {}
repeat with x in tagged_items
set end of taggedPosix to item location of x
end repeat
end tell
(*
tell application "Nifty Box"
set f to folder "test" -- top level folder
set taggedList to tagged nbitems of f
set taggedPosix to {}
repeat with i in taggedList
set end of taggedPosix to item location of i
end repeat
end tell
*)
--i get files in folder which should be checked for tags--outout is posix path names--and put all files in list "filesList"
set myDir to (choose folder)

-- we have to remove the trailing / from the folder path so the
-- returned paths from the find command are correct
set posix_folder to text 1 thru -2 of (POSIX path of myDir) -- text 1 thru -2 of (POSIX path of myDir) to remove trailing forward slash

-- use find to quickly find the items in this_folder
-- also filter out invisible files and files in invisible folders
-- also filter files inside of package files like ".app" files
set allfilesPosix to paragraphs of (do shell script "find " & quoted form of posix_folder & " -name \"*.*\" ! -path \"*/.*\" ! -path \"*.app/*\" ! -path \"*.scptd/*\" ! -path \"*.rtfd/*\" ! -path \"*.xcodeproj/*\"") as list
--set allfilesPosix to allfilesPara as list
--i do the color labels


--this line marks the end of the POSIX code
--------------------------------------
--i convert both lists, taggedPosix->taggedList and allfilesPosix->allfilesList to AppleScript References
set taggedList to {}
repeat with i in taggedPosix
set end of taggedList to POSIX file i
end repeat

set allfilesList to {}
repeat with i in allfilesPosix
set end of allfilesList to POSIX file i
end repeat


set untaggedPosix to {}
repeat with theItem in allfilesPosix
if theItem is not in taggedPosix then set end of untaggedPosix to (contents of theItem)
end repeat
get untaggedPosix

--
-------------------------------------
set untaggedList to {}
repeat with i in untaggedPosix
set end of untaggedList to POSIX file i
end repeat
get untaggedList

tell application "Finder"
repeat with i in untaggedList
set label index of (item i) to theIndex
end repeat
end tell

Tuesday, February 28, 2012

Customizing Microsoft Word with AppleScript

Original HOWTO Document

Customizing Microsoft Word with AppleScript
The first step in doing anything in Microsoft Word or Microsoft Excel with AppleScript is to download the tutorials for MS Office 2004 from Microsoft.

I started using Xelatex for my linguistics papers and I decided that I didn’t really need to go that hardcore. I decided to write scripts to boss around MS Word and make it imitate the quality of my Xelatex papers (which are great, but you can’t just copy and paste them due to the nature of code).
Outline of my idea

Use Microsoft Excel to set variables
Use AppleScript to generate a plist from excel file stored in ~/Library/Preferences
Use AppleScript to retrieve those properties from the plist in ~/Library/Preferences and apply them to a Word Document.


The following is an example Excel Document with can be used to set various settings in a Microsoft Word Document.
Setting Value Type of Value Accepted Comments
boldHeading1 TRUE boolean
boldHeading2 TRUE boolean
boldHeading3 TRUE boolean
boldHeading4 TRUE boolean
boldHeading5 TRUE boolean
boldHeading6 TRUE boolean
boldHeading7 TRUE boolean
boldHeading8 TRUE boolean
boldHeading9 TRUE boolean
boldNormal FALSE boolean
footerLine TRUE boolean
headerLine TRUE boolean
italicsHeading1 FALSE boolean
italicsHeading1 FALSE boolean
italicsHeading2 FALSE boolean
italicsHeading3 FALSE boolean
italicsHeading4 FALSE boolean
italicsHeading5 FALSE boolean
italicsHeading6 FALSE boolean
italicsHeading7 FALSE boolean
italicsHeading8 FALSE boolean
italicsHeading9 FALSE boolean
italicsNormal FALSE boolean
sectionNumbering TRUE boolean number each heading
smallcapscaptionFigures TRUE boolean
smallcapscaptionTables TRUE boolean
coverdateAuto TRUE boolean if false, applescript tries to use the dateCustom field
coverPage TRUE boolean makes cover appear on new page
footerlineThickness 25 integer points
headerlineThickness 25 integer
sizeHeading1 15 integer font size
sizeNormal 12 integer
marginpageL 2 integer sets page margin
marginpageT 2 integer sets page margin
marginpageR 2 integer sets page margin
marginpageB 2 integer sets page margin
sizeHeading2 14 integer
sizeHeading3 13 integer
sizeHeading4 12 integer
sizeHeading5 12 integer
sizeHeading6 12 integer
sizeHeading7 12 integer
sizeHeading8 12 integer
sizeHeading9 12 integer
colorHeading1 black string
colorHeading2 black string color word
colorHeading3 black string color word
colorHeading4 black string color word
colorHeading5 black string color word
colorHeading6 black string color word
colorHeading7 black string color word
colorHeading8 black string color word
colorHeading9 black string color word
colorNormal black string color word
fontcaptionFigures CMU Serif Roman string system font name
fontHeading1 CMU Serif Roman string system font name
fontHeading2 CMU Serif Roman string system font name
fontHeading3 CMU Serif Roman string system font name
fontHeading4 CMU Serif Roman string system font name
fontHeading5 CMU Serif Roman string system font name
fontHeading6 CMU Serif Roman string system font name
fontHeading7 CMU Serif Roman string system font name
fontHeading8 CMU Serif Roman string system font name
fontHeading9 CMU Serif Roman string system font name
fontNormal CMU Serif Roman string "normal" style font
sectionnumberingType list template 5 of list gallery 3 string this refers to the list numbering menu in word
textfooterL 1 string sets text of footer left
textfooterM 1 string sets text of footer middle
textfooterR 1 string sets text of footer right
textheaderL 1 string sets text of header left
textheaderM 1 string sets text of header middle
textheaderR 1 string sets text of header right
fontcaptionTables CMU Serif Roman string
coverTitle 1 string
coverAuthor 1 string
coverdateCustom 1 string
coverDegree Master of Linguisics string
coverUniversity Universität Innsbruck string
coverPresentedto presented to the faculty of blah blah string if blank, not included

AppleScript to Read Excel to Plist file
The following script only needs to be run once. It will generate the property list file for the “Apply Settings to Word Document” script. If you make any changes to the settings, it will need to be run again to replace the old plist file.

set theFile to (choose file with prompt "Please select a Microsoft Excel file") as string

set theColumn to text returned of (display dialog "Please select a range" default answer "A2:C72")

set theRange to (theColumn) as string

tell application "Microsoft Excel"

open workbook workbook file name theFile

set aList to get value of range "A2:C72" of active sheet

end tell

--set up new plist file using the empty dictionary list item as contents

set userDir to (path to current user folder) as string

set plistfilePath to userDir & "Library:Preferences:msword.Academicsetup.plist"

tell application "System Events"

set the parent_dictionary to make new property list item with properties {kind:record}

set outFile to make new property list file with properties {contents:parent_dictionary, name:plistfilePath}

--add values to plist

tell outFile

repeat with i from 1 to (count of aList)

set keyName to (item 1 of (item i of aList) as string)

set keyValue to (item 2 of (item i of aList) as string)

set keyType to (item 3 of (item i of aList) as string)

if keyType is "boolean" then

make new property list item at end with properties ¬

{kind:boolean, name:keyName, value:keyValue}

end if

if keyType is "string" then

make new property list item at end with properties ¬

{kind:string, name:keyName, value:keyValue}

end if

if keyType is "integer" then

--important step to avoid real numbers (with decimals), coerse keyValue to be integer

-- create an integer entry

make new property list item at end with properties ¬

{kind:number, name:keyName, value:(keyValue as integer)}

end if

end repeat

end tell

end tell
say "Dieses Skript ist fertig!"
AppleScript to Apply Settings to Word Document

(*USE EXISTING PLIST START*)

set userDir to (path to current user folder) as string

set plistfilePath to userDir & "Library:Preferences:msword.Academicsetup.plist"

global plistfilePath

(*USE EXISTING PLIST*)

tell application "Microsoft Word"

tell active document

(**)

(**)

(**)

(**)

(**)

(**)

(**)

(**)

(**)

(**)

end tell

(**)

end tell

on pL(theItem)

tell application "System Events"

set p_list to property list file (my plistfilePath)

value of property list item (theItem as string) of p_list

end tell

end pL

Saturday, February 25, 2012

Use Nifty Box to keep track of important files and folders on your Mac.

Free Downloads (by the way, Leap does the same thing as Nifty Box, but costs 60 dollars)
Nifty Box Download/
OpenMeta Exporter DownloadUPDATE: OpenMeta Exporter is no longer needed.

Step 1: Create an AppleScript droplet for adding Nifty Box tags to files easily.
on open (the_Droppings)
set theTags to text returned of (display dialog "Pick a tag! (you can add more than one tag by leaving a space between each word" default answer "")
if theTags is equal to "" then
display dialog "You must enter a tag"
exit repeat
else
set defaulDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set thelistofTags to text items of theTags
set AppleScript's text item delimiters to defaulDelims
tell application "Nifty Box"
set theFile to the_Droppings
set x to add path POSIX path of theFile
x add tags named thelistofTags
tags of x
end tell
end if
end open

Step 2: Add the Droplet to your Finder Window and drag files to it.

Step 3: Add some tags.

Step 4: This is the result in Nifty Box.

Step 5: Use Spotlight to find files using Nifty Box meta tags (Convert meta tags from Nifty Box to OpenMeta with the OpenMeta Exporter). UPDATE: The newer version of Nifty Box will auto export to Spotlight wihtout the need for OpenMeta Exporter. Tags even show up in the Finder>More Info window.

Friday, February 24, 2012

How to create Terminal aliases in Mac OS X Lion

How to make Mac OS X Terminal Aliases
#first create a file called .bash_profile in your home directory
touch ~/.bash_profile
#then add your aliases with the following
nano ~/.bash_profile
#OR
open -a TextEdit ~/.bash_profile
# add things like this
alias text="open -a TextEdit"
alias dt="cd ~/Desktop"

Thursday, February 23, 2012

Organize Your Mac with Tags Nifty Box!

www.nifty-box.com

CORE 2 2.83 GHZ QUAD 9550, Main Board: EP45T-USB3P, Video: GeForce 9500 GT 1024 MB HACKINTOSH

I have a fully functional Hackintosh running OS X Lion 10.7.3 (11D50b) using the EP45T-USB3P Motherboard and the 9500GT video card.

Typical Problems I have had in previous OS X versions, but overcome easily in Lion 10.7.3 thanks to TonyMacx86:
Open GL working
Sound Working

Process:
Follow the instuctions at the following website:
http://tonymacx86.blogspot.com/2011/10/unibeast-install-mac-os-x-lion-using.html

Use the following settings on Multibeast 4.2.1



Unzip and put the resulting file in your /System/Library/Extensions Folder:
http://dl.dropbox.com/u/47530119/NVEnabler%2064.kext.zip

Repair Permissions and delete create new cache. Use this program for doing that easily:
http://dl.dropbox.com/u/47530119/RepairKexts%20Permission.app.zip

Saturday, February 18, 2012

Run Bash file in Finder in Terminal with Easy Automator Service

You can create a Automator service to run bourne script files (bash) from Finder with a simple right click. This service will open a new Terminal window and execute whatever bourne script you like. It can be modified to run other scripts in terminal.

Step 1: Open Automator and select service


Step 2: see image and pay attention to the red annotations


Applescript Text for copying:
on run {input, parameters}
set thescriptFile to quoted form of POSIX path of (input as string)
(*
--quoted form adds '' around thescriptFile
--without POSIX Path it looks like 'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
--with POSIX path of quoted form it looks like /'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
--CORRECT with quoted form of POSIX path it looks like 'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
*)
tell application "Terminal"
activate
do script "sh " & thescriptFile & "; 8"
end tell
say "Making backup in new terminal window"
end run

Step 3: right click a bash file (must be an executable bash script [chmod a+x the file from terminal--i have another automator service for that])

Sunday, February 12, 2012

New Bash Scripters (Bourne Shell)

When experimenting with BASH scripts, the most often forgotten, yet important steps:

make your script executable
sudo chmod a+x nameofyourshell.sh

label script at the beginning to inform everyone (including the computer) that your script is a bash script with the following on line 1:
#!/bin/sh

Sunday, January 29, 2012

reference_information.txt file

Get Specific events within date range with icalbuddy
icalbuddy -sc -f eventsFrom:'November 28, 2011' to:'December 2, 2011'

käme es mir gelegen = es wäre gut für mich.


How do I put GRUB into the boot sector of a partition instead of putting it in the MBR via grub-install?
grub-install --root-directory=/boot /dev/hdb
update-grub
MBR:
boot sector = 448 bytes - 2 equal bytes at the end = 446=bs
partition table info = 46 bytes after boot sector
Totaling to bs=512 count=1

tar -jxf for tar.bz2
hdiutil for conversion img and dmg
hdiutil convert source.img/iso -format UDRW -o output.dmg/***
hdiutil convert some.dmg -format UDTO -o some.dd
optional: conv=sync,noerror

The MBR consists of _three_ parts, not two:

1. The first 446 bytes contain the boot loader.
2. The next 64 bytes contain the partition table (4 entries, each 16 bytes).
3. The last 2 bytes contain the identifier 0xAA55 (or 0x55AA, I forgot).

To copy the boot loader only, one *must* use "bs=446". To copy the partition table only, one must use "bs=1 skip=446 count=64".
To exclude the partition table count=1 bs=446
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The Hackintosh Bootloader (GUID or FDisk partition schemes)
boot0
typically placed in the boot code secion of MBR for a darwin-only system. On some systems, it may not be installed and an alternative primary boot manager (which has its own code) such as LILO may be used.

boot1h
goes in the boot section (first .5KB) of a HFS+ partition, and has enough code to parse an HFS+ volume header, find the extents associated with the "HFS+ Startup File" and load it.

boot
Boot is what is reffered to by the Startup File extents for a HFS+ volume. This is the second-stage loader which is in charge of presenting the list of bootable3 volumes, and if applicatble, loading a kernel + extensions from the filesystem. (cdboot is a modified version of boot for use on CDs)

For a standalone sing-partition HFS install, you would ideally have:
A) boot0 - in the MBR, LILO, or GRUB
B) boot1h - in the first 512-bytes of the HFS+ partition
C) boot - pointed to by the HFS+ Startup File

To install boot0 in the MBR
dd if=/path/to/file/boot0 of=dev/diskX bs=400 count=1

To install boot1h in the bootsector
dd if=/path/to/file/boot1h of=dev/diskXsY bs=512 count=1

To set the HFS+ Startup File
/path/to/file/startupfiletool /dev/rdiskXsY /path/to/file/boot

It is convetional to install boot0, boot1h, and boot to /usr/standalone/i386

In addition, if you are using a FDisk partition scheme, you must set the boot partition of the disk active.
fdisk -e /dev/rdiskX
Ignore the error "fdisk: could not open MBR file..."
p "varifies partition"
f 1 "set partition active"
w "write to partition"
y (yes you are sure)
exit (to quit)

update latex files with sudo mktexlsr

My howto file in ~/howto

#####################################
#this is text file with useful tips##
#####################################
download youtube with command: youtube-dl
get all links on website: get-links.py #optional: > atextfile.txt

download packages and all dependencies
use 'python grabpackages.py -o '
then copy and paste contents of to command line and push enter to initiate download into current directory.

To save the MBR to a file (this contains the partition table too):
dd if=/dev/hda of=hda-mbr-full bs=512 count=1

To save the MBR, without the partition table, to a file:
dd if=/dev/hda of=hda-mbr-nopart bs=446 count=1

To save a boot sector (e.g. partition 3) to a file:
dd if=/dev/hda3 of=hda3-bootsect bs=512 count=1
MBR TOTAL SIZE = 446 + 64 + 2 = 512
446 bytes - Bootstrap.
64 bytes - Partition table.
2 bytes - Signature.

Use 446 bytes to overwrite or restore your /dev/XYZ MBR boot code only with the contents of $mbr.backup.file.
Use 512 bytes to overwrite or restore your /dev/XYZ the full MBR (which contains both boot code and the drive's partition table) with the contents of $mbr.backup.file.

for example, if identically sized partitions on origin and destination,
this command will copy 512 bytes (MBR) from sda to sdb disk.
dd if=/dev/sda of=/dev/sdb bs=512 count=1

different size partitions-two step process
dd if=/dev/sda of=/tmp/mbrsda.bak bs=512 count=1
dd if=/tmp/mbrsda.bak of=/dev/sdb bs=446 count=1

The above commands will preserve the partitioning schema.
####################
####################



edit a file in root mode with textedit
$ gksudo gedit

set vlc as main media player for everything
gksudo gedit the following and do a search & replace of totem and replace with vlc
/usr/share/applications/defaults.list

check size of directory
$ du -h /foldername --human readable
$ du -ah /foldername --all filenames along with the directory
$ du -c /foldername --grand total

usb-creator-gtk

find router address
$ route -n
OR
$ netstat -r

remove empty folders
find . -type d -empty -delete

recursively move files
find . -name '*.flv' -exec mv {} flv \;

how to extract tar.gz
tar xyvf

how to setup various settings, like auto open a mounted drive in nautilus
gconf-editor

python documentation server
pydoc -g
#####BASH WILDCARDS######
Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given

Great Free and Useful Software for Apple Macs

ProVoc
Purpose: Learning via flashcards.
Details: It is no longer being developed, but works under Lion. Another developer has used the ProVoc code to create iVocabulary and has also created an iOS app for it. You can create an excel document and export it to a text file, which will import to Provoc properly (if using korean characters or similar, eport to UTF-16 txt). Use column A (language 1), B (language 2), and C (for comments).
Location: http://www.arizona-software.ch/provoc/

Saturday, January 28, 2012

Making Microsoft Word 2011 Mac produce (Xe)(La)TeX Style Outlines for Academic Papers with Applscript

(*
Academic Paper Setup

Copyright © 2012 Jonathan Komar

Just kidding there is no copyright. Open Source rules!

You may use this code however you like. It would be nice 
if you made reference to the original code when sharing.

THINGS TO DO:
find a fix for changing font color of headings without hardcoding it.
fix headings 4-9
*)



(*<Properties to be set by the user*)
--number suffix corresponds to heading 1, heading 2, etc.
--NOTE: To change the coloring of headings, it must be hardcoded. must find a fix.
property fontName1 : "CMU Serif Roman"
property fontName2 : "CMU Serif Roman"
property fontName3 : "CMU Serif Roman"
property fontName4 : "CMU Serif Roman"
property fontName5 : "CMU Serif Roman"
property fontName6 : "CMU Serif Roman"
property fontName7 : "CMU Serif Roman"
property fontName8 : "CMU Serif Roman"
property fontName9 : "CMU Serif Roman"
property fontSize1 : 15
property fontSize2 : 14
property fontSize3 : 13
property fontSize4 : 12
property fontSize5 : 12
property fontSize6 : 12
property fontSize7 : 12
property fontSize8 : 12
property fontSize9 : 12
property boldTF : true
property italicTF : false
property highlightTF : false
(*Properties to be set by the user>*)

tell application "Microsoft Word"
    tell active document
        (*<normal code BLOCK*)
        set name of font object of Word style style normal to "CMU Serif Roman"
        set font size of font object of Word style style normal to 12
        set bold of font object of Word style style normal to false
        set italic of font object of Word style style normal to false
        set color index of font object of Word style style normal to black
        (*normal code BLOCK>*)
        
        
        (*<heading 1 code BLOCK*)
        set name of font object of Word style style heading1 to fontName1
        set font size of font object of Word style style heading1 to fontSize1
        set bold of font object of Word style style heading1 to boldTF
        set italic of font object of Word style style heading1 to italicTF
        set color index of font object of Word style style heading1 to black
        --set paragraph format left indent of paragraph format of Word style style heading1 to (centimeters to points centimeters 0) --indent sections relative to margin
        --set tab stop position of tab stop of Word style style heading1 to (centimeters to points centimeters 1)
        --set tab hanging indent of paragraph format of Word style style heading1 to count 1
        (*heading 1 code BLOCK>*)
        (*<heading 2 code BLOCK*)
        set name of font object of Word style style heading2 to fontName1
        set font size of font object of Word style style heading2 to fontSize1
        set bold of font object of Word style style heading2 to boldTF
        set italic of font object of Word style style heading2 to italicTF
        set color index of font object of Word style style heading2 to black
        (*heading 2 code BLOCK>*)
        (*<heading 3 code BLOCK*)
        set name of font object of Word style style heading3 to fontName1
        set font size of font object of Word style style heading3 to fontSize1
        set bold of font object of Word style style heading3 to boldTF
        set italic of font object of Word style style heading3 to italicTF
        set color index of font object of Word style style heading3 to black
        (*heading 3 code BLOCK>*)
        (*<heading 4 code BLOCK*)
        set name of font object of Word style style heading4 to fontName1
        set font size of font object of Word style style heading4 to fontSize1
        set bold of font object of Word style style heading4 to boldTF
        set italic of font object of Word style style heading4 to italicTF
        set color index of font object of Word style style heading4 to black
        (*heading 4 code BLOCK>*)
        (*<heading 5 code BLOCK*)
        set name of font object of Word style style heading5 to fontName1
        set font size of font object of Word style style heading5 to fontSize1
        set bold of font object of Word style style heading5 to boldTF
        set italic of font object of Word style style heading5 to italicTF
        set color index of font object of Word style style heading5 to black
        (*heading 5 code BLOCK>*)
        (*<heading 6 code BLOCK*)
        set name of font object of Word style style heading6 to fontName1
        set font size of font object of Word style style heading6 to fontSize1
        set bold of font object of Word style style heading6 to boldTF
        set italic of font object of Word style style heading6 to italicTF
        set color index of font object of Word style style heading6 to black
        (*heading 6 code BLOCK>*)
        (*<heading 7 code BLOCK*)
        set name of font object of Word style style heading7 to fontName1
        set font size of font object of Word style style heading7 to fontSize1
        set bold of font object of Word style style heading7 to boldTF
        set italic of font object of Word style style heading7 to italicTF
        set color index of font object of Word style style heading7 to black
        (*heading 7 code BLOCK>*)
        (*<heading 8 code BLOCK*)
        set name of font object of Word style style heading8 to fontName1
        set font size of font object of Word style style heading8 to fontSize1
        set bold of font object of Word style style heading8 to boldTF
        set italic of font object of Word style style heading8 to italicTF
        set color index of font object of Word style style heading8 to black
        (*heading 8 code BLOCK>*)
        (*<heading 9 code BLOCK*)
        set name of font object of Word style style heading9 to fontName1
        set font size of font object of Word style style heading9 to fontSize1
        set bold of font object of Word style style heading9 to boldTF
        set italic of font object of Word style style heading9 to italicTF
        set color index of font object of Word style style heading9 to black
        (*heading 9 code BLOCK>*)
        
    end tell
    
    (*<apply numbering to the sections code BLOCK*)
    set selFind to find object of selection --selects text of execute find command
    clear formatting selFind --reset selFind just to make sure
    set style of selFind to style heading1 --set style we are looking for
    execute find selFind find text "" wrap find find continue with find format and match forward
    if found of selFind is true then
        --display dialog (get content of text object of selection) --for debugging only
        (*<code BLOCK word__set paragraph style*)
        --I apply the formatting to the previously found text
        set myLT to list template 5 of list gallery 3 of active document
        apply list format template (list format of text object of selection) ¬
            list template myLT
    end if
    (*Apply numbering to the sections code BLOCK>*)
    
    
    
    
    
    
    
    
    
    
    
    
    (*******************************************
    (*<code BLOCK word_get style.scpt*)
    --i select the header 1 stuff
    set selFind to find object of selection --selects text of execute find command
    clear formatting selFind --reset selFind just to make sure
    set style of selFind to style heading1 --set style we are looking for
    execute find selFind find text "" wrap find find continue with find format and match forward
    if found of selFind is true then
        --display dialog (get content of text object of selection) --for debugging only
        (*<code BLOCK word__set paragraph style*)
        --I apply the formatting to the previously found text
        set theRange to text object of active document --i say where to apply the script
        set myStyle to Word style of object of selection of active document --debug only
        --set myStyle to make new Word style at active document with properties ¬
        {name local:"Section", style type:style type paragraph}
        tell font object of selFind
            set name to fontName1
            set font size to fontSize1
            set bold to true
        end tell
        set myLT to list template 5 of list gallery 3 of active document
        apply list format template (list format of text object of selection) ¬
            list template myLT
        (*code BLOCK word__set paragraph style>*)
        --set style of theRange to myStyle --i actually apply the settings
        update styles active document
    end if
    (*code BLOCK word_get style.scpt>*)
    *********************************)
    
end tell

Friday, January 20, 2012

Applescript: Open multiple websites in tabs with Firefox

#open websites in tabs with firefox
set list_Sites to {"http://www.google.at", "http://www.yahoo.com"}

tell application "Firefox"
activate
repeat with a in list_Sites
do shell script "open -a Firefox" & space & quoted form of a
end repeat
end tell

Thursday, January 19, 2012

Python Script to Open Webpages in Firefox tabs (or any browser supported by the python webbrowser library)

  #python  
import webbrowser  
a = ['http://www.google.com/reader','http://www.yahoo.com/','http://www.facebook.com/']  
  for x in a:  
       webbrowser.get('firefox').open_new_tab(x)  

You just need to copy and paste that code into a text file and save it as something like "opensite.py" (better to use the .py extension)

Make it executable running the following command in terminal:
 sudo chmod a+x opensite.py  

Run it either in the command line with
 python /path/to/opensite.py  

Or create a launcher (you can do this in Ubuntu easily by right clicking on the desktop)

Firefox Download Files to Specific Folders Frequently

Hey firefox users:

Useful tip for firefox (if you use firefox). Ever wish you download files directly to a specific folder without having to move them later. For example, I have a folder structure like this:

~/University/Winter2011/Media Class

I want to download documents for my Media Class into that folder frequently.

You can get an "add-on" for firefox called "save file to" and it will allow you to easily set up such folders as download locations. I am using save file to 2.2"

I find it to be quite useful!

Friday, January 6, 2012

Typing/Typesetting Korean with xelatex (unicode latex)

The following is a link to the PDF file generated by the xelatex source below:
http://www.mediafire.com/?4w382gzlk9kry04">82gzlk9kry04

 Xelatex Source:  
 %XELATEX DOCUMENT  
 \documentclass[12pt]{extreport}  
 \usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}  
 %\usepackage[margin=1in, paperwidth=5.5in, paperheight=8.5in]{geometry}  
 \usepackage{fancyhdr}  
 \pagestyle{fancy}  
 \lhead{\textsc{Jonathan Komar}} \chead{\textsc{Koreanisch}} \rhead{\textsc{Seite\hspace{.2cm}-\thepage-}}   
 \lfoot{\textsc{Version 2}} \cfoot{\textsc{}} \rfoot{\textsc{erstellt mit XeLatex am 06. Jänner 2012}}  
 \renewcommand{\headrulewidth}{0.1pt}   
 \renewcommand{\footrulewidth}{0.1pt}  
 \usepackage{xcolor}%add color support for text  
 \usepackage{xltxtra}  
 \usepackage{fontspec}%included in xltxtra allows for switching fonts in document with \fontspec{fontname} command  
 \usepackage{xunicode}%included in xltxtra  
 \setmainfont[Mapping=tex-text]{Linux Libertine O}%set main global font  
 \newfontfamily{\korean}{Batang}%creates custom command to temporarily change to korean font.  
 \definecolor{red}{RGB}{255,0,0}  
 \definecolor{blue}{RGB}{27,0,55}  
 \definecolor{orange}{RGB}{255,68,0}  
 \begin{document}  
 ㅈ  
 %%  
 \begin{table}[htdp]  
 \caption{Selbstlaute \textsc{(Einzellaute)}}  
 \begin{center}  
 \begin{tabular}{|c|c|c|}  
 Vokale & IPA \\\hline  
 \korean{{\Huge ㅇㅏ}} & /a/ or /ɐ/ \\  
 \korean{{\Huge ㅇㅓ}} & /ə/\\  
 \korean{{\Huge ㅇㅗ}} & /o/\\  
 \korean{{\Huge ㅇㅜ}} & /u/\\  
 \korean{{\Huge ㅇㅡ}} & /ɯ/\\  
 \korean{{\Huge ㅇㅣ}} & /i/\\  
 \korean{{\Huge ㅇㅔ}}&/e/\\  
 \korean{{\Huge ㅇᅢ}}&/ɛ/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Selbstlaute \textsc{(Doppellaute)}}  
 \begin{center}  
 \begin{tabular}{|c|c|}  
 \korean{{\Huge ㅇㅑ}} & /ja/ or /jɐ/ \\  
 \korean{{\Huge ㅇㅕ}} & /jə/\\  
 \korean{{\Huge ㅇㅛ}} & /jo/\\  
 \korean{{\Huge ㅇㅠ}} & /ju/\\  
 \korean{{\Huge ㅇㅖ}}&/je/ \\   
 \korean{{\Huge ㅇㅒ}}& /jɛ/\\   
 \korean{{\Huge ㅇㅟ}}&/wi/ \\   
 \korean{{\Huge ㅇㅞ}}&/we/\\   
 \korean{{\Huge ㅇㅙ}}&/wɛ/\\  
 \korean{{\Huge ㅇㅘ}}&/wa/\\  
 \korean{{\Huge ㅇㅢ}}&/ɰi/\\  
 \korean{{\Huge ㅇㅝ}}&/wʌ/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Konsonanten}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|}  
 Phonem&IPA\\\hline  
 \korean{{\Huge ㅂ}}&/b/ or /p/\tiny{or /m/ (vor \korean{ㅁ,ㄴ,ㄹ})}\\  
 \korean{{\Huge ㅃ}}&/p͈ʰ/\\  
 \korean{{\Huge ㅍ}}&/pʰ/\\  
 \korean{{\Huge ㅁ}}&/m/\\  
 \korean{{\Huge ㄷ}}&/d/ or /t/\\  
 \korean{{\Huge ㄸ}}&/t͈ʰ/\\  
 \korean{{\Huge ㅌ}}&/tʰ/\\  
 \korean{{\Huge ㄴ}}&/n/\\  
 \korean{{\Huge ㅈ = [  ]}}&/ʤ/ or /ʧ/\\%problem here prints like a diff character  
 \korean{{\Huge ㅉ}}&/ʤ͈ʰ/\\  
 \korean{{\Huge ㅊ = [  ]}}&/ʧʰ/\\%problem here prints like a diff character  
 \korean{{\Huge ㄱ}}&/g/ or /k/\\  
 \korean{{\Huge ㄲ}}&/k͈ʰ/\\  
 \korean{{\Huge ㅋ}}&/kʰ/\\  
 \korean{{\Huge ㅇ}}&/ŋ/{\tiny (Endsilbe)}\\  
 \korean{{\Huge ㅅ}}&/s/ or /ʃ/\\  
 \korean{{\Huge ㅆ}}&/s͈ʰ/\\  
 \korean{{\Huge ㄹ}}&/l/ oder /ɾ/\\  
 \korean{{\Huge ㅎ}}&/h/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 See footnotes for ⟨◌͈⟩\footnote{The IPA symbol ⟨◌͈⟩ (a subscript double straight quotation mark, shown here with a placeholder circle) is used to denote the tensed consonants /p͈/, /t͈/, /k͈/, /t͈ɕ/, /s͈/. Its official use in the Extensions to the IPA is for 'strong' articulation, but is used in the literature for faucalized voice.}  
 \footnote{Faucalized voice, also called hollow or yawny voice, is the production of speech sounds with an expanded laryngeal cavity. It contrasts with harsh voice, in which the larynx is compressed.  
 There is no symbol for faucalized voice in the standard IPA. Diacritics seen in the literature include the strong articulation diacritic ([a͈]) of the Extensions to the IPA. I}  
 %%  
 \begin{table}[htdp]  
 \caption{Ich studiere Sprachwissenschaft.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|}  
 Sprachwissenschaft & studieren & Höfflichkeitsform\\  
 \korean{{\Huge 언어학}} & \korean{{\Huge 공부}} & \korean{{\Huge 합니다}}\\  
 /ɛn ɛ hak & go bu & hap ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Am Morgen esse ich Reis.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|}  
 Morgen&am&Reis&Objmarke&esse&Höfflichkeitsform\\  
 \korean{{\Huge 아침}}&\korean{{\Huge 에}}&\korean{{\Huge 밥}}&\korean{{\Huge {\color{red}{을}}}}&\korean{{\Huge 먹}}&\korean{{\Huge {\color{red}{습}}니다}}\\  
 /a tʃim & e & bap & ɯl & mɯk & ʃɯm ni da/\\  
 &&&&& sɯm ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Am Wochenende kaufe ich Alkohol.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|}  
 Wochenende&am&Alkohol&Objmarke&kaufe&Höfflichkeitsform\\  
 \korean{{\Huge 주말}}&\korean{{\Huge ㅇㅔ}}&\korean{{\Huge 술}}&\korean{{\Huge {\color{red}{을}}}}&\korean{{\Huge 사}}&\korean{{\Huge {\color{red}{ㅂ}}니다}}\\  
 &&&&\korean{{\Huge(삽)}}&\korean{{\Huge(니다)}}\\  
 /tʃu mal & e & sul & ɯl & ʃa & m ni da/\\  
 &immer mit Objekt&&&\\  
 & eines anderes Wortes  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Am Abend esse ich Schinkenbrot.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|}  
 Abend&am&Schinkenbrot&Objmarke&esse&Höfflichkeitsform\\  
 \korean{{\Huge 저녁}}&\korean{{\Huge 에}}&\korean{{\Huge 햄뻥}}&\korean{{\Huge {\color{red}{을}}}}&\korean{{\Huge 먹}}&\korean{{\Huge {\color{red}{슴}}니다}}\\  
 /ʤə njəg & e & hɛm p͈ʰɯɳ & ɯl & mək & ʃɯm ni da/\\  
 &&&&&sɯm ni da\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Im Sommer treffe ich am Mittag normalerweise einen Freund.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|c|c|c|}  
 Sommer&im&Mittag&am&normalerweise&einen Freund&Objmarke&treffe&Höfflichkeitsform\\  
 \korean{여름}&\korean{에}&\korean{점심}&\korean{에}&\korean{보통}&\korean{친구}&\korean{ {\color{red}{를}}}&\korean{만 나}&\korean{ {\color{red}{ㅂ}}니다}\\  
 &&&&&&&\korean{(만남)}&\korean{(니다)}\\  
 /jə rɯm & e & ʤɛm sim & e & bo to & ʧʰin gul & rɯl & man na & m ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Ich bin ein Mann}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|c}  
 ich&ein Mann&bin&Höfflichkeitsform\\  
 \korean{{\Huge 저는}}&\korean{{\Huge 남자}}&\korean{{\Huge 이}}&\korean{{\Huge {\color{red}{ㅂ}}니다}}\\  
 &&\korean{{\Huge {(입)}}}&\korean{{\Huge (니다)}}\\  
 /ʤə nɯn & nam ʤa & i & m ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \section*{Haben + \korean{{\Huge 이 가}}}  
 %%  
 \begin{table}[htdp]  
 \caption{Ich habe ein Handy.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|c}  
 Handy&habe ich&Objmarke&Höfflichkeitsform\\  
 \korean{{\Huge (학디)?}}&\korean{{\Huge {\color{red}{가}}}}&\korean{{\Huge 이}}&\korean{{\Huge {\color{red}{릅}}니다}}\\  
 &&\korean{{\Huge {}}}&\korean{{\Huge }}\\  
 /? & da & i & sɯm ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 %%  
 \begin{table}[htdp]  
 \caption{Ich habe Wasser.}  
 \begin{center}  
 \begin{tabular}{|c|c|c|c|c|c|c}  
 Wasser&habe ich&Objmarke&Höfflichkeitsform\\  
 \korean{{\Huge 물}}&\korean{{\Huge {\color{red}{이}}}}&\korean{{\Huge 이}}&\korean{{\Huge {\color{red}{릅}}니다}}\\  
 &&\korean{{\Huge {}}}&\korean{{\Huge }}\\  
 /mul & i & i & sɯm ni da/\\  
 \end{tabular}  
 \end{center}  
 \label{default}  
 \end{table}%  
 \end{document}  

Thursday, January 5, 2012

BASH Script Download Programs and ALL dependencies for offline installation

This is useful for linux users who may not always have an internet connection for apt-get and wish to create a database of offline installable deb files.
Note to basic users:

You can install *.deb files with the following command (ignore the $, just means its on the command line)
 $ sudo dpkg -i *.deb  

I have written and tested this script in Ubuntu 11.04 Desktop. FYI It is a work in progress. What I am trying to say is that it is not idiot-proof.

HOW DOES IT WORK?

You make a plain text file, typing each program you wish to install. Put spaces in between programs but no carriage return. Example: python2.6 alarm easyshutdown gimp
Another example:
Command line example of program list (although you could use a text editor):
1:  $ echo "vlc alarm-clock apache2 conky curl ffmpeg" > programs.txt  

Copy this script to a text editor, save as installsource-generator.sh
Before you can run a new script, you have to make it executable with the command:

1:  $ sudo chmod a+x installsource-generator.sh  
Before running the script, open the script and edit the variable where you would like to set up an installsource directory. (you can find it in between all of the pound signs towards the beginning)

Ensure stable internet connection (the command wget -c will be used to download files, which will attempt to reconnect if link is lost)
Make sure you download grabpackages.py and move it to the /usr/local/bin folder with the command
1:  $ sudo mv /folder/of/grabpackages.py /usr/local/bin  
2:  $ sudo chmod a+x grabpackages.py /usr/local/bin/grabpackages.py #(to make it executable)  


You are now ready to download programs with ALL dependencies
To run, simple invoke the following command (you may need to type 'sudo -s' without quotes first)
1:  $ sudo sh installsource-generator.sh nameoftextfile.txt  


HERE IS THE CODE:

 #!/bin/sh  
 #this program generates an installsource of packages + all dependencies from an array of files. use the spaces  
 #installsource-generator  
 #version 2.0  
 #requires grabpackages.py in /usr/local/bin (must make it executable ie sudo chmod a+x grabpackages.py)  
 #SUMMARY OF ACTIONS  
 #get list of package names (programs)  
 #mkdir in installsource for each package  
 #run grabpackages.py on each package and output to the corresponding list of dependencies (sh file) to folder (auto appropriately name for each program)  
 #chmod a+x on each sh file from grabpackages.py  
 #ask user whether to install the deb files  
 ##################################################  
 ##################################################  
 ##################################################  
 ##################################################  
 ############VARIABLES TO BE SET BY USER###########  
 ##################################################  
 #i set installLoc  
 installLoc="$HOME/installsource-ubuntu/generated"  
 ##################################################  
 ##################################################  
 #create installsource directory if its not there already  
 mkdir -p "$installLoc"  
 #array=( one two three )#i am an example of an array  
 #testfor$1input  
 if test ! -s "$1"  
 then  
  echo 'syntax> installsource-generator listofprograms.txt'  
 fi  
 #i assign array to variable  
 #declare -a arrayFile  
 #array=`cat "$1"`  
 #declare -a arrayFile=($array)  
 ##################################################  
 ##################################################  
 for i in `cat "$1"`  
 do  
   # do whatever on $i  
  echo "creating folder $i"  
  mkdir "$installLoc/$i"  
  echo "downloading packages with grabpackages.py and saving to folder "$i""  
  grabpackages.py -o "$installLoc/$i/$i.sh" "$i"  
  #make files executable  
  sudo chmod a+x "$installLoc/$i/$i.sh"  
  fullPath="$installLoc/$i/"  
  sed -i "s|wget -c|wget -c -P $fullPath|g" "$installLoc/$i/$i.sh"  
  sh "$installLoc/$i/$i.sh"  
 done  
 ##################################################  
 echo "COMPLETED ALL DOWNLOADS AND PREPARING TO INSTALL"  
 echo "WOULD YOU LIKE TO INSTALL ALL DOWNLOADED PACKAGES?"  
 read installAnswer  
 if [ $installAnswer = "y" ]; then  
 echo 'STARTING INSTALL'  
 for i in `cat "$1"`  
 do  
   # do whatever on $i  
  echo "installing package $1.sh"  
  sudo dpkg -i "$installLoc/$i/*.sh"  
 done  
  sudo dpkg -i $mediaDrive/$installsource/*.deb  
  echo 'install complete, script complete'  
 else  
  echo 'no install, script complete'  
 fi  

BASH script quotations review.







I often write Bourne Scripts using variables of file locations. Here are several examples of text inputs with results for reference:

#!/bin/sh
folder1="~/Desktop/scriptexp/subfolder 1"
echo $folder1
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo "$folder1"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder1'
#RESULT>$folder1<
#########################################
folder2='~/Desktop/scriptexp/subfolder 1'
echo $folder1
#RESULT>~/Desktop/scriptexp/subfolder 1"<
echo "$folder1"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder1'
#RESULT>$folder1<
#########################################
folder3="~/Desktop/scriptexp"
folder4="subfolder 1"
echo "$folder3/$folder4"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo "$folder3/$folder4"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder3/$folder4'
#RESULT>$folder3/$folder4<
#****************************************
echo "$folder3/"folder4""
#RESULT>~/Desktop/scriptexp/folder4<
#****************************************
#****************************************
echo "$folder3/'folder4'"
#RESULT>~/Desktop/scriptexp/'folder4'<
#########################################
text1="I like to "go" running."
echo $text1
#RESULT>I like to go running.<
echo "$text1"
#RESULT>I like to go running.<
echo '$text1'
#RESULT>$text1<
text2="I like to 'go' running."
echo $text2
#RESULT>I like to 'go' running.<
echo "$text2"
#########################################
text3='I like to "go" running.'
echo $text3
echo "here"
#RESULT>I like to "go" running.<
echo "$text3"
#RESULT>I like to "go" running.<
echo '$text3'