Heikos Little Helpers

From Wurst-Wasser.net
Jump to navigation Jump to search

About

Heiko's Little Helpers are a bunch of AppleScripts I wrote to do frequently needed jobs for me...
Originally I programmed an application named Sake to do that, but it became more complex than I anticipated...that's why I decided to discontinue Sake and switch to FastScripts.

What?

There are some things I often to by hand - this really bothered me. Therefore I sought a way to do this more efficiently.

System Requirements

Setup

  • Install FastScripts
  • Download this scripts (link below), unpack and move them either into...
    • ~/Library/Scripts (usable for your own user only)
    • /Library/Scripts (usable for all users of your Mac)

Usage

  • Example: Archive Selected File/Folder.scpt
    • Select the files you want to archive, in this case "Miscellaneous Scripts", and select Archive this! in FastScripts menu...
      Heikoslittlehelpers20091222a1.png
    • ...and you get this:
      Heikoslittlehelpers20091222b1.png

What it can do for you!

Script Function
Paste Timestamp.scpt Pastes a timestamp like "2009-12-22 16:29" into the current text editor.
Paste Log Timestamp.scpt Pastes timestamp like this: "2009-12-22, 16:32, hk: ". This is my favourite. I don't remember what it was like before I used this!
Archive Selected File/Folder.scpt You'll gonna love this: Creates an archive from your selected file/folder and adds an timestamp to the filename. That's sooo handy for my source backups.
Leo Selected Text.scpt Looks up selected text in http://www.leo.org .
Look Up Selected Text In Dictionary.scpt Looks up selected text in MacOS X's Dictionary.
Google Selected Text.scpt Looks up selected text in Google
Google Selected Text For Images.scpt Looks up selected text in Google Image search
Dial Selected Number.scpt Dials selected number with iLink Direct
Decrease Volume.scpt Decreases system volume
Increase Volume.scpt Decreases system volume
Mute Volume.scpt Mutes system volume
Toggle Mute.scpt Toggles muting of system volume
iTunes Rating Scripts.scpt Rates selected or current tracks
Google Album Artwork Of Current Track.scpt Guess what.
Google Album Artwork Of Selected Track.scpt Guess what.
Google Lyrics Of Current Track.scpt Guess what.
Google Lyrics Of Selected Track.scpt Guess what.
Paste iTunes Current Track.scpt Pastes the current iTunes track like this: "The Beez - Die Warteschleife - Die Warteschleife (Radio Edit)".
Create Checksum File.scpt Creates checksum files for the selected file(s).
Compare Checksum File.scpt Checks whether the checksum files exist and match, or not.

Download

Media:HeikoLittleHelpers.zip

Sources

You might be interested in how that stuff works. Take a look:


HeiMac:Little Helpers Scripts heiko$ ./getSourceOfAppleScripts.sh 

Dumping ./Archive Selected File or Folder.scpt 2010-04-23 23:10:41.452 osadecompile[34906:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* Script to archive selected files/folders and name them 

History:

2009-11-12, 12.10, hk: First version is working.

ToDo:

-strip leading directories from archive, so that they don't get created when expanding...



*)
on run (argv)
tell application "Finder"
set selectedItems to selection
if ((count of selectedItems) is 1) then
# else if ((count of selectedItems) is greater than 1) then
set theItem to first item in selectedItems #as alias
#get class of theItem
set theItemClass to class of theItem
log theItemClass
set theItemName to name of theItem
set theItemContainer to (container of theItem) as alias
set itemPath to POSIX path of (theItem as alias)
set itemContainerPath to POSIX path of theItemContainer
if (theItemClass is folder) then (* not using type because it's localized, class is not *)
(* remove trailing "/" *)
set l to length of itemPath
set itemPath to text 1 thru (l - 1) of itemPath
log "shortened: " & itemPath
else
# mach nix
end if
set zipFileName to theItemName & " " & my timestamp() & ".zip"
#set zipFilePath to itemContainerPath & "" & theItemName & "_" & my timestamp() & ".zip"
#trasht alle dirs im zip set cmd to "zip -j -r \"" & zipFilePath & "\" \"" & itemPath & "\"" # -m
set cmd to "cd \"" & itemContainerPath & "\" && zip -r \"" & zipFileName & "\" \"" & theItemName & "\"" # -m
# set cmd to "zip \"" & zipFilePath & "\" -x .\\* \"" & itemPath & "\""
log cmd
do shell script cmd
else
display dialog "Please select one files/folders in Finder." buttons "Allright, I do whatever you say!"
end if
end tell
end run









(* get a time stamp *)
on timestamp()
set dateNow to current date
set dateYear to year of dateNow
set dateMonth to addLeadingZeros(2, (month of dateNow as number) as string)
set dateDay to addLeadingZeros(2, day of dateNow)
set dateHour to addLeadingZeros(2, hours of dateNow)
set dateMinute to addLeadingZeros(2, minutes of dateNow)
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & " " & dateHour & "-" & dateMinute) as string
end timestamp

(* Liefert von einer Zahl n leading zeros zurück *)
on addLeadingZeros(zeroesCount, value)

(* nimmt die letzten zeroesCount Stellen des Strings *)
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)
log "newNumber: " & newNumber

return (newNumber)
end addLeadingZeros



Dumping ./Copy Selected Mail To Clipboard.scpt 2010-04-23 23:10:41.558 osadecompile[34909:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* copies selected mail from apple mail to clipboard as text *)

tell application "Mail"

set theSelectedMessages to selection

if (count theSelectedMessages) is greater than 0 then

repeat with oneSelectedMessage in theSelectedMessages
tell oneSelectedMessage
set t to all headers
set t to t & return & content
log t
tell application "System Events"
set the clipboard to t
end tell
end tell
end repeat

else
display dialog "You haven't selected any message..." buttons {"Doh!"}
end if

end tell

Dumping ./Dial Selected Number.scpt 2010-04-23 23:10:41.706 osadecompile[34912:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "System Events" to keystroke "c" using {command down}
delay 0.1
set someword to the clipboard

tell application "direct.app" to «event ****DiMC» given «class DEST»:someword as string


Dumping ./Google Images Selected Text.scpt 2010-04-23 23:10:41.849 osadecompile[34915:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "System Events" to keystroke "c" using {command down}
delay 0.1
get the clipboard
set someword to the clipboard

tell application "Safari"
activate
open location "http://google.com/images?q='" & someword & "'"
end tell


Dumping ./Google Selected Text.scpt 2010-04-23 23:10:42.003 osadecompile[34918:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "System Events" to keystroke "c" using {command down}
delay 0.1
set someword to the clipboard

tell application "Safari"
activate
open location "http://google.com/search?q='" & someword & "'"
end tell

Dumping ./iTunes Currently Playing Track/*****.scpt 2010-04-23 23:10:42.155 osadecompile[34921:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
set r to 5
set t to current track
set rating of t to 100 / 5 * r
end tell

Dumping ./iTunes Currently Playing Track/****.scpt 2010-04-23 23:10:42.313 osadecompile[34925:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
set r to 4
set t to current track
set rating of t to 100 / 5 * r
end tell

Dumping ./iTunes Currently Playing Track/***.scpt 2010-04-23 23:10:42.419 osadecompile[34928:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
set r to 3
set t to current track
set rating of t to 100 / 5 * r
end tell

Dumping ./iTunes Currently Playing Track/**.scpt 2010-04-23 23:10:42.529 osadecompile[34931:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
set r to 2
set t to current track
set rating of t to 100 / 5 * r
end tell

Dumping ./iTunes Currently Playing Track/*.scpt 2010-04-23 23:10:42.632 osadecompile[34934:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
set r to 1
set t to current track
set rating of t to 100 / 5 * r
end tell

Dumping ./iTunes Currently Playing Track/Google Album Artwork Of Current Track.scpt 2010-04-23 23:10:42.754 osadecompile[34937:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
# set tName to name of current track
set tArtist to artist of current track
set tAlbum to album of current track
# set queryText to tArtist & " " & tAlbum
set queryText to "\"" & tArtist & "\" \"" & tAlbum & "\""
end tell

tell application "Safari"
activate
open location "http://google.com/images?q=" & queryText
end tell


Dumping ./iTunes Currently Playing Track/Google Lyrics Of Current Track.scpt 2010-04-23 23:10:42.877 osadecompile[34940:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"

set tArtist to artist of current track
set tName to name of current track
--set queryText to "lyrics " & tArtist & " " & tName
set queryText to "lyrics \"" & tArtist & "\" \"" & tName & "\""
set queryText to my replace_chars(queryText, "&", "%26") # see http://www.degraeve.com/reference/urlencoding.php
end tell

tell application "Safari"
activate
open location "http://google.com/search?q=" & queryText
end tell

# see http://forums.macosxhints.com/archive/index.php/t-26666.html
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars


Dumping ./iTunes Currently Playing Track/Open Current Track's Lyrics in TextEdit.scpt 2010-04-23 23:10:43.008 osadecompile[34943:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* Just for reading - it's more comfy than in iTune's info-window *)
tell application "iTunes"

set l to lyrics of current track

tell application "TextEdit"
activate

set newDoc to make new document
set text of newDoc to l

end tell

end tell

Dumping ./iTunes Currently Playing Track/Paste Current iTunes Track with Album.scpt 2010-04-23 23:10:43.131 osadecompile[34946:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
get player state
if player state is not paused and player state is not stopped then
tell current track
set message to artist & " - " & album & " - " & name
end tell
# set artist to artist of current track
# set album to album of current track
# set title to name of current track
set the clipboard to message
tell application "System Events" to keystroke "v" using {command down}
end if
end tell


Dumping ./iTunes Currently Playing Track/Paste Current iTunes Track.scpt 2010-04-23 23:10:43.293 osadecompile[34949:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
get player state
if player state is not paused and player state is not stopped then
tell current track
set message to artist & " - " & name
end tell
set the clipboard to message
tell application "System Events" to keystroke "v" using {command down}
end if
end tell


Dumping ./iTunes Currently Playing Track/Show Current Track's Whole Album in Library.scpt 2010-04-23 23:10:43.461 osadecompile[34952:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

# http://dougscripts.com/itunes/itinfo/info02.php
# http://dougscripts.com/itunes/itinfo/itunes72info.php
tell application "iTunes"
#activate

display dialog "Not Working yet!"
return



set ct to current track
set tName to name of ct
set tArtist to artist of ct
set tAlbum to album of ct
set queryText to tArtist & " " & tAlbum
#KO set albumTracks to search l for tAlbum only albums
#OK set albumTracks to search playlist "Library" for tAlbum only albums
set albumTracks to (every file track of playlist "Library" whose album contains tAlbum and artist contains tArtist)
log albumTracks

# Maybe I can select the Library and the tracks with some dirty tricks
tell application "System Events"
tell process "iTunes"
get window 1
#get every item of window 1
#get outlines of window 1
#get buttons of window 1
#get browsers of window 1
#get drawers of window 1
#get lists of window 1
#get text fields of window 1
# Plenty of UI Elements:
get UI elements of window 1
# Splitter Group?
set sg to splitter group of window 1
get UI elements of sg
set u to UI elements of sg
log u # empty
# Grow Area?
set g to grow area 1 of window 1
get UI elements of g
set u to UI elements of g
log u #empty
# scroll area 1 (the yellow thingy)
set s to scroll area 1 of window 1
get UI elements of s
set u to UI elements of s
log u

end tell
end tell



# Ab hier Bastelbude: #######################

#set t to first item in albumTracks
#log location of t
#set view of (browser window 1) to parent of t

(* geht nicht:
reveal file track id 120028 of library playlist id 84927 of source id 48 *)
# set t to first item in albumTracks
# reveal t

(* geht:
reveal file track id 489116 of user playlist id 488505 of source id 48

*)
# set t to current track
# reveal t



#KO reveal first item in albumTracks

#KO reveal playlist "Library"

#? reveal current track
#KO reveal (first item in albumTracks) of playlist "Library"

#KO reveal first item in albumTracks


(*OK set t to current track
reveal t *)
#OK reveal current track

# log name of view of (browser window 1)
#log name of view of (front browser window)

#
#set view of (browser window 1) to library playlist
#set view of (browser window 1) to library playlist 1

#set view of front browser window to library playlist 1


# set l to library playlist
# log l



# log name of l
#log parent of l
# log source of l


#log browser window
# set view of front browser window to playlist "Library"
#set view of front browser window to library playlist

# set view of front browser window to user playlist "Library" of source "Library"

#set selection to albumTracks
#browser window
end tell



Dumping ./iTunes Currently Playing Track/Speak Current Track.scpt 2010-04-23 23:10:43.623 osadecompile[34955:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
get player state
if player state is not paused and player state is not stopped then
tell current track
set message to "Now playing " & name & " of the album " & album & " from " & artist
end tell
tell AppleScript to say message using "Victoria" (* see http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as304.html *)
end if
end tell


Dumping ./iTunes Currently Playing Track/Volume/Decrease (-) Volume.scpt 2010-04-23 23:10:43.769 osadecompile[34958:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

set whatToDo to "dec" (* can be "inc", "dec", "mute" *)


(* Get the current output volume (on a scale from 1 to 100) and convert it to a scale from 1 to 16 as seen when using the volume keys *)
set currentVolume to output volume of (get volume settings)
set scaledVolume to round (currentVolume / (100 / 16))

if (whatToDo contains "mute") then
set volume with output muted
else
if (whatToDo contains "inc") then
(* Use this code to increase the volume by a certain interval *)
set soundInterval to 1
set scaledVolume to scaledVolume + soundInterval
if (scaledVolume > 16) then
set scaledVolume to 16
end if
else if (whatToDo contains "dec") then
(* OR use this code to decrease the output volume by 1 *)
set scaledVolume to scaledVolume - 1
if (scaledVolume < 0) then
set scaledVolume to 0
end if
else
set scaledVolume to scaledVolume
end if

(* After using one of the above, the volume needs to be set to the new level (before which we must convert it back to the 1..100 scale) *)
set newVolume to round (scaledVolume / 16 * 100)
set volume output volume newVolume

end if

Dumping ./iTunes Currently Playing Track/Volume/Increase (+) Volume.scpt 2010-04-23 23:10:43.887 osadecompile[34961:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

set whatToDo to "inc" (* can be "inc", "dec", "mute" *)


(* Get the current output volume (on a scale from 1 to 100) and convert it to a scale from 1 to 16 as seen when using the volume keys *)
set currentVolume to output volume of (get volume settings)
set scaledVolume to round (currentVolume / (100 / 16))

if (whatToDo contains "mute") then
set volume with output muted
else
if (whatToDo contains "inc") then
(* Use this code to increase the volume by a certain interval *)
set soundInterval to 1
set scaledVolume to scaledVolume + soundInterval
if (scaledVolume > 16) then
set scaledVolume to 16
end if
else if (whatToDo contains "dec") then
(* OR use this code to decrease the output volume by 1 *)
set scaledVolume to scaledVolume - 1
if (scaledVolume < 0) then
set scaledVolume to 0
end if
else
set scaledVolume to scaledVolume
end if

(* After using one of the above, the volume needs to be set to the new level (before which we must convert it back to the 1..100 scale) *)
set newVolume to round (scaledVolume / 16 * 100)
set volume output volume newVolume

end if

Dumping ./iTunes Currently Playing Track/Volume/Mute Volume.scpt 2010-04-23 23:10:43.992 osadecompile[34964:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

set whatToDo to "dec" (* can be "inc", "dec", "mute" *)


(* Get the current output volume (on a scale from 1 to 100) and convert it to a scale from 1 to 16 as seen when using the volume keys *)
set currentVolume to output volume of (get volume settings)
set scaledVolume to round (currentVolume / (100 / 16))

if (whatToDo contains "mute") then
set volume with output muted
else
if (whatToDo contains "inc") then
(* Use this code to increase the volume by a certain interval *)
set soundInterval to 1
set scaledVolume to scaledVolume + soundInterval
if (scaledVolume > 16) then
set scaledVolume to 16
end if
else if (whatToDo contains "dec") then
(* OR use this code to decrease the output volume by 1 *)
set scaledVolume to scaledVolume - 1
if (scaledVolume < 0) then
set scaledVolume to 0
end if
else
set scaledVolume to scaledVolume
end if

(* After using one of the above, the volume needs to be set to the new level (before which we must convert it back to the 1..100 scale) *)
set newVolume to round (scaledVolume / 16 * 100)
set volume output volume newVolume

end if

Dumping ./iTunes Currently Playing Track/Volume/Toggle Mute.scpt 2010-04-23 23:10:44.100 osadecompile[34967:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* Mute/Unute
*)
set _muted to (get (output muted of (get volume settings)))
if _muted is false then
set volume with output muted
else
set volume without output muted
end if

Dumping ./iTunes Selected Tracks/*****.scpt 2010-04-23 23:10:44.188 osadecompile[34970:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

repeat with aTrack in sel

set r to 5
set rating of aTrack to 100 / 5 * r

end repeat
end if
end tell

Dumping ./iTunes Selected Tracks/****.scpt 2010-04-23 23:10:44.308 osadecompile[34973:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

repeat with aTrack in sel

set r to 4
set rating of aTrack to 100 / 5 * r

end repeat
end if
end tell

Dumping ./iTunes Selected Tracks/***.scpt 2010-04-23 23:10:44.427 osadecompile[34976:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

repeat with aTrack in sel

set r to 3
set rating of aTrack to 100 / 5 * r

end repeat
end if
end tell

Dumping ./iTunes Selected Tracks/**.scpt 2010-04-23 23:10:44.540 osadecompile[34979:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

repeat with aTrack in sel

set r to 2
set rating of aTrack to 100 / 5 * r

end repeat
end if
end tell

Dumping ./iTunes Selected Tracks/*.scpt 2010-04-23 23:10:44.644 osadecompile[34982:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

repeat with aTrack in sel

set r to 1
set rating of aTrack to 100 / 5 * r

end repeat
end if
end tell

Dumping ./iTunes Selected Tracks/Google Album Artwork Of Selected Track.scpt 2010-04-23 23:10:44.752 osadecompile[34985:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...
set sel to a reference to selection
if ((count of sel) > 1) then
activate
set res to display dialog "Are you sure you want Artwork for more than one track?" buttons {"I know what I'm doing", "Ah, no, thank you!"}
#if
log res
if button returned of res is not "I know what I'm doing" then
return
end if
end if
repeat with aTrack in sel
set tArtist to artist of aTrack
set tAlbum to album of aTrack
set queryText to "\"" & tArtist & "\" \"" & tAlbum & "\""
tell application "Safari"
activate
open location "http://google.com/images?q=" & queryText & ""
end tell
end repeat
end if
end tell



Dumping ./iTunes Selected Tracks/Google Lyrics Of Selected Track.scpt 2010-04-23 23:10:44.872 osadecompile[34988:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"

if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 1 or trackCount is less than 1 then
activate
set msg to "You selected " & trackCount & " tracks. Please select exactly one. Thanks a bunch."
set res to display dialog msg buttons {"Sure!"}
return
end if

set aTrack to first item in sel

set tArtist to artist of aTrack
set tName to name of aTrack
set queryText to "lyrics \"" & tArtist & "\" \"" & tName & "\""
set queryText to my replace_chars(queryText, "&", "%26") # see http://www.degraeve.com/reference/urlencoding.php

tell application "Safari"
activate
# open location "http://google.com/search?q='" & queryText & "'"
open location "http://google.com/search?q=" & queryText & ""
end tell

end if

end tell


# see http://forums.macosxhints.com/archive/index.php/t-26666.html
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars


Dumping ./iTunes Selected Tracks/Paste Selected iTunes Tracks with Album.scpt 2010-04-23 23:10:45.027 osadecompile[34991:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"

if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to do this with the selected " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

set message to ""
repeat with aTrack in sel

tell aTrack
set message to message & artist & " - " & album & " - " & name & return
end tell

end repeat

set the clipboard to message

tell application "System Events" to keystroke "v" using {command down}

end if
end tell


Dumping ./iTunes Selected Tracks/Paste Selected iTunes Tracks.scpt 2010-04-23 23:10:45.171 osadecompile[34994:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"

if selection is not {} then -- there ARE tracks selected...

set sel to a reference to selection
set trackCount to count sel
if trackCount is greater than 23 then
set msg to "Are you sure, you want to do this with the selected " & trackCount & " tracks?"
set res to display dialog msg buttons {"Sure!", "Actually, no."}
if button returned of res is not "Sure!" then
return
end if
end if

set message to ""
repeat with aTrack in sel

tell aTrack
set message to message & artist & " - " & name & return
end tell

end repeat

set the clipboard to message

tell application "System Events" to keystroke "v" using {command down}

end if
end tell


Dumping ./iTunes Selected Tracks/Play Single Track.scpt 2010-04-23 23:10:45.325 osadecompile[34997:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* 
Ever wondered how you can play a single track? Think of it: You navigate to a track in your music library, and you want to play it. Just this one.
Yes: iTunes offers no method of doing this (except creating a new playlist, adding the track, playing the track und deleting the playlist afterwards. Yes, this sucks).

The bad news: I have no better solution.
Now the good news: You don't have to do it yourself! Here's the script that does it all for you: (place into ~/Library/iTunes/Scripts/ or ~/Library/Scripts/)
*)

global tempplaylistname
on run
(* Init *)

set tempplaylistname to "temp"

(* Create new playlist, if not existing *)
tell me to set pl to newtempplaylist()

(* selected track -> pl *)
tell application "iTunes"

(* remember old playlist *)
set oldpl to view of (browser window 1)

(* Now the magic... *)
try
get class of selection
# log selection
# if ((count of selection) is greater than 0) then
set t to first item in selection

(* track into playlist *)
duplicate t to pl

(* playlist repeat off *)
set song repeat of pl to off

(* playlist to front *)
try
#set view of front window to playlist pl
#set view of browser window to pl
#set view of (browser window 1) to user playlist pl (*Fuck! (iTunes got an error: A descriptor type mismatch occurred.)*)
set view of (browser window 1) to pl (* Works with iTunes 9 *)
on error (e)
log "Fuck! (" & e & ")"
end try

(* play track *)
play first item of tracks of pl

(* Wait until track played or stopped *)
set dur to duration of t
repeat dur times
if player state is not playing then exit repeat
delay 1.0
end repeat

(* restore old playlist *)
set view of (browser window 1) to oldpl
on error (e)
display dialog "Select something, you weenie!" buttons "Yes, your highness!"
end try

(* delete temp playlist *)
delete pl
end tell
end run

(* Create a temp playlist we will delete afterwards *)
on newtempplaylist()
tell application "iTunes"
set pl to make new user playlist with properties {name:tempplaylistname & " as of " & (current date) as string}
end tell
return pl
end newtempplaylist

Dumping ./iTunes Selected Tracks/Remove Leading "01" from Title.scpt 2010-04-23 23:10:45.439 osadecompile[35000:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

tell application "iTunes"

tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...
set sel to a reference to selection
repeat with aTrack in sel

set oldName to name of aTrack
log "Processing :" & oldName

set cmd to "echo \"" & oldName & "\" | sed s/01\\ //\\g"
tell application "Finder"
set newName to do shell script cmd
end tell
log "Setting new name: " & newName

set name of aTrack to newName

end repeat
end if
end tell

end tell

Dumping ./Leo Selected Text.scpt 2010-04-23 23:10:45.566 osadecompile[35003:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* Copy selected string to clipboard *)
tell application "System Events"
(* Try using Cmd-C *)
set oldClipboard to the clipboard
keystroke "c" using {command down}
set someword to the clipboard
if (oldClipboard is equal to someword) then
log "Most likely you held some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..)"
(* Trying to invoke "Copy" Menu command *)
set appName to name of current application
# my menu_click({appName, my menuEditLocalized(), my menuItemEditCopyLocalized(), ""})
tell application "System Events"
set procs to every process
repeat with p in procs
if frontmost of p is true then
set proc to p
end if
end repeat
#set proc to items of processes whose frontmost is true
#set proc to item 1 of processes
get proc
#click menu item "Copy" of ((proc)'s (menu bar 1)'s (menu bar item "Edit"))
set menuBar to menu bar 1 of proc
set editMenu to menu bar item whose name is (my menuEditLocalized())
return 0
end tell
end if
#delay 0.5
end tell


(* Open Browser with query *)
tell application "Safari"
activate
open location "http://dict.leo.org/?search='" & someword & "'"
end tell


(* get localized copy menu item name *)
on menuItemEditCopyLocalized()
tell AppleScript
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"
set languageCode to do shell script cmd
if (languageCode is "de") then
return "Kopieren"
else if (languageCode is "en") then
return "Copy"
else
log "WTF?"
return ""
end if
end tell
end menuItemEditCopyLocalized


(* get localized copy menu name *)
on menuEditLocalized()
tell AppleScript
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"
set languageCode to do shell script cmd
if (languageCode is "de") then
return "Bearbeiten"
else if (languageCode is "en") then
return "Edit"
else
log "WTF?"
return ""
end if
end tell
end menuEditLocalized




(* This came from http://www.macosxhints.com/article.php?story=20060921045743404 *)
on menu_click(mList)
local appName, topMenu, r

-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"

-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)

-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
local f, r

-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse

Dumping ./Look Up Selected Text In Dictionary.scpt 2010-04-23 23:10:45.721 osadecompile[35006:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* Unfortunately Dictionary is not scriptable but can only be automated with Automator. However there is always the dirty way using System Events. That's what I did to script Dictionary.
*)

(* Get selected text *)
tell application "System Events" to keystroke "c" using {command down}

(* Bring Dictionary to foreground *)
tell application "Dictionary" to activate


(* Paste selected text *)
tell application "System Events" to keystroke "v" using {command down}


(* Look up *)
# tell application "System Events" to keystroke return




Dumping ./Paste Log Timestamp.scpt 2010-04-23 23:10:45.863 osadecompile[35009:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

on run (argv)
# set oldClip to the clipboard

set the clipboard to my timestamp()


tell application "System Events" to keystroke "v" using {command down}

# set the clipboard to oldClip
end run


(* get a time stamp *)
on timestamp()
set dateNow to current date
set dateYear to year of dateNow
set dateMonth to (month of dateNow as number)
set dateDay to addLeadingZeros(2, day of dateNow)
set dateHour to addLeadingZeros(2, hours of dateNow)
set dateMinute to addLeadingZeros(2, minutes of dateNow)
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & ", " & dateHour & ":" & dateMinute & ", hk: ") as string
end timestamp

(* Liefert von einer Zahl n leading zeros zurück *)
on addLeadingZeros(zeroesCount, value)

(* nimmt die letzten zeroesCount Stellen des Strings *)
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)
log "newNumber: " & newNumber

return (newNumber)
end addLeadingZeros



Dumping ./Paste Timestamp.scpt 2010-04-23 23:10:46.009 osadecompile[35012:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

set the clipboard to my timestamp()


tell application "System Events" to keystroke "v" using {command down}



(* get a time stamp *)
on timestamp()
set dateNow to current date
set dateYear to year of dateNow
set dateMonth to (month of dateNow as number)
set dateDay to addLeadingZeros(2, day of dateNow)
set dateHour to addLeadingZeros(2, hours of dateNow)
set dateMinute to addLeadingZeros(2, minutes of dateNow)
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & " " & dateHour & ":" & dateMinute) as string
end timestamp

(* Liefert von einer Zahl n leading zeros zurück *)
on addLeadingZeros(zeroesCount, value)

(* nimmt die letzten zeroesCount Stellen des Strings *)
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)
log "newNumber: " & newNumber

return (newNumber)
end addLeadingZeros


Dumping ./Reply Mail With Quote.scpt 2010-04-23 23:10:46.166 osadecompile[35015:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osadecompile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

(* History:
2010-02-21, 16:44, hk: First version.
* If name contains "," reverse order!--DONE
* get original text--DONE
* check if already quoted, if not-> quote--DONE
* Leere Zeilen auch quoten--DONE
* Reply & set new content--DONE

Bug: Erkennung des schon gequoteten buggt!--?

ToDo:

*)


tell application "Mail"
# tell message viewer
# get selected messages
# end tell
set selectedMessages to selection
set selectedMessagesCount to (count selectedMessages)
if selectedMessagesCount > 0 then
if selectedMessagesCount > 23 then
set res to display dialog "Are you sure you want to reply on " & selectedMessagesCount & " messages?" buttons {"No", "Maybe", "Yes"}
if button returned of res is not "Yes" then
return
end if
end if
(* Now, do the magic! *)
repeat with selectedMessage in selectedMessages
tell selectedMessage
set smSender to sender
(* cut the email-address *)
tell me to set smSenderName to cutString of smSender by "<"
(* If name contains "," cut the part before the "," and add it at the end (this way "Doe, John" will get "JD" instead of "DJ") *)
if smSenderName contains "," then
log "foo"
tell me to set smSenderNameSurname to cutString of smSenderName by ","
log smSenderNameSurname
tell me to set smSenderNameFirstname to cutStringRemainder of smSenderName by ","
log smSenderNameFirstname
set smSenderName to (smSenderNameFirstname & " " & smSenderNameSurname) as text (* yes, that's ugly *)
log smSenderName
end if
(* get initials of the name *)
tell me to set smInitials to initialsOfName(smSenderName)
(* get text of mail and walk lines... http://www.mactech.com/articles/mactech/Vol.21/21.07/WorkingWithText/index.html *)
set smText to content
set smTextQuoted to ""
#log smText
#set smTextLineCount to count paragraphs of smText

(* Zeilen (=Paragraphs) abklappern *)
repeat with p in (paragraphs of smText)

(* Get line length *)
set lineLength to (length of p)
if lineLength > 5 then
set lineLength to 5
end if

if lineLength > 0 then
set pBegin to characters 1 thru lineLength of p
else
set pBegin to ""
end if

if pBegin contains ">" then
(* is quoted -> just concatenate strings *)
#log "already quoted: " & pBegin
set smTextQuoted to smTextQuoted & (p as string) & return
else

#if pBegin does not contain ">" then
(* not quoted yet, quote! *)
set smTextQuoted to smTextQuoted & smInitials & "> " & (p as string) & return
#else
# (* already quoted *)
# set smTextQuoted to smTextQuoted & (p as string) & return
#end if
#else
#set smTextQuoted to smTextQuoted & (p as string) & return
end if

end repeat (* repeat with paragraphs *)
log "quoted text: " & return & smTextQuoted
end tell # tell selectedMail

(* Backup quoting behaviour *)
tell application "Mail" to set quotingSetting to quote original message
tell application "Mail" to set quote original message to false

(* now reply *)
set newMessage to reply selectedMessage with opening window and reply to all
if newMessage is false then
log "Gee, reply failed."
else
tell newMessage
log newMessage
#set content of newMessage to "foo" -- smTextQuoted
# make new content with properties {text:"smTextQuoted"}
log (content)
log (subject)
log (sender)
log (to recipients)
#make new to recipient with properties {address:"MY ADDRESS"}
log (to recipients)
#make new content with t
#log "s: " & (contents as text)
set content to "foo"
set content to smTextQuoted
#make new content with properties {text:"MY text"}
end tell
end if # reply worked

(* Restore quoting behaviour *)
tell application "Mail" to set quote original message to quotingSetting

end repeat (* repeat with mails *)
else
log ("You might want to select a message first")
end if
end tell

(* Now get the first characters of every word (Initials) *)
on initialsOfName(sendername)
set initials to ""
repeat with oneWord in (words of sendername)
set initials to initials & first character of oneWord
end repeat
return initials
end initialsOfName

(* cuts all the text following the first occurance of the searchstring 'd' *)
to cutString of t by d
set oldd to text item delimiters
set text item delimiters to d
set t to t's text items
set t to first item in t
set text item delimiters to oldd
t
end cutString

(* returns what cutString has cut off! *)
to cutStringRemainder of t by d
set oldd to text item delimiters
set text item delimiters to d
set t to t's text items
set wordCount to count t
if (wordCount > 1) then
set t to items 2 through wordCount in t
end if
set text item delimiters to oldd
t
end cutStringRemainder

(* Diese Funktion ersetzt einen String innerhalb eines strings durch einen anderen String. Quelle: http://macscripter.net/viewtopic.php?id=13008 *)
to changeSubString of t from s to r
set d to text item delimiters
set text item delimiters to s
set t to t's text items
set text item delimiters to r
tell t to set t to beginning & ({""} & rest)
set text item delimiters to d
t
end changeSubString

HeiMac:Little Helpers Scripts heiko$