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