Heikos Little Helpers

From Wurst-Wasser.net
Revision as of 20:49, 14 July 2011 by Heiko (talk | contribs) (Setup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

(this page will soon be obsolete and will move to AppleScript Launcher)

<flattr url="http://www.wurst-wasser.net/" />{{#TwitterFBLike:right}}

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 switched 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

Download

Media:HeikosLittleHelpers20100925.zip

Setup

  • Install FastScripts
  • Download this scripts (link below), unpack and move them either into...
    • ~/Library/Scripts (usable for your own user only)
      ...or...
    • /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

  • Files
    • Archive Selected File or Folder.scpt
    • Compare Checksum File.scpt
    • Create Checksum File.scpt
    • File Merge.scpt
    • File Split.scpt
  • InDesign
    • Copy Image.scpt
  • iTunes Currently Playing Track
    • *.scpt
    • **.scpt
    • ***.scpt
    • ****.scpt
    • *****.scpt
    • Google Album Artwork Of Current Track.scpt
    • Google Lyrics Of Current Track.scpt
    • Open Current Track's Lyrics in TextEdit.scpt
    • Paste Current iTunes Track with Album.scpt
    • Paste Current iTunes Track.scpt
    • Show Current Track's Whole Album in Library.scpt
    • Speak Current Track.scpt
    • Volume
      • Decrease (-) Volume.scpt
      • Increase (+) Volume.scpt
      • Mute Volume.scpt
      • Toggle Mute.scpt
  • iTunes Selected Tracks
    • *.scpt
    • **.scpt
    • ***.scpt
    • ****.scpt
    • *****.scpt
    • Export….scpt
    • Google Album Artwork Of Selected Track.scpt
    • Google Lyrics Of Selected Track.scpt
    • Paste Selected iTunes Tracks with Album.scpt
    • Paste Selected iTunes Tracks.scpt
    • Play Single Track.scpt
    • Remove Leading "01" from Title.scpt
  • Mail
    • Copy Selected Mail To Clipboard.scpt
    • Reply Mail With Quote (buggy).scpt
    • Save Selected Mails As RTF_buggy.scpt
    • Save Selected Messages As Text.scpt
  • Searches
    • Google Images Selected Text.scpt
    • Google Selected Text.scpt
    • Leo Selected Text.scpt
    • Look Up Selected Text In Dictionary.scpt
  • Text conversion
    • Kenny.scpt
    • Lowercase.scpt
    • Mirror.scpt
    • ROT5.scpt
    • ROT5+13.scpt
    • ROT13.scpt
    • ROT18.scpt
    • ROT47.scpt
    • ROTrandom.scpt
    • Uppercase.scpt
  • Timestamps
    • Paste Log Timestamp.scpt
    • Paste Timestamp.scpt
  • Zome More Tools
    • Activate Screensaver.scpt
    • Deactivate Screensaver.scpt
    • Dial Selected Number.scpt
    • FStream
      • Speak Radio Station Name.scpt
      • Toggle Playback.scpt

Social Media

{{#TwitterFBLike:right|}} <flattr url="http://www.wurst-wasser.net/" />

Sources

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


Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Files/Archive Selected File or Folder.scpt

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Files/Compare Checksum File.scpt

(* Script to check an md5 checksum

ToDo:

- escape quotes in filenames, because that will result in an error
- do the fileCount over all, not only every one selected folder (multiple dialogs)
- optional crc using "cksum" instead of md5 (cksum only on Snow Leopard (10.6) and maybe higher)

*)

(* Global Vars *)
global fileCount, logMessage, dialogTooMuchFilesMessage01, dialogTooMuchFilesMessage02, dialogTooMuchFilesYes, dialogTooMuchFilesNo, dialogNothingSelectedMessage, dialogNothingSelectedButton, dialogErrorOccurredMessage, dialogErrorOccurredButton, dialogChecksumFileMissingMessage01, dialogChecksumFileMissingMessage02, dialogChecksumFileMissingButton, dialogErrorWord, dialogAttentionWord, dialogChecksumMismatchMessage01, dialogChecksumMismatchMessage02


(* Properties (English) *)
property dialogAttentionWordEnglish : "ATTENTION! "
property dialogErrorWordEnglish : "Error: "
property dialogTooMuchFilesMessage01English : "Are you sure you want to check checksums for "
property dialogTooMuchFilesMessage02English : " files?"
property dialogTooMuchFilesYesEnglish : "Yes, sure!"
property dialogTooMuchFilesNoEnglish : "Hell, no!"
property dialogNothingSelectedMessageEnglish : "Please select one or more files in Finder."
property dialogNothingSelectedButtonEnglish : "Allright, I do whatever you say!"
property dialogErrorOccurredMessageEnglish : "One or more errors occured:" & return & return
property dialogErrorOccurredButtonEnglish : "Doh!"
property dialogChecksumFileMissingMessage01English : "The checksum file for the file \""
property dialogChecksumFileMissingMessage02English : "\" is missing or corrupted!"
property dialogChecksumFileMissingButtonEnglish : "Gee!"
property dialogChecksumMismatchMessage01English : "The checksum for the file \""
property dialogChecksumMismatchMessage02English : "\" does not match!"
property dialogChecksumsMatchMessageEnglish : "The checksums match!"
property dialogChecksumsMatchButtonEnglish : "Great!"

#property dialogChecksumMismatchButtonEnglish : "Gee!"
(* Properties (Deutsch) *)
property dialogAttentionWordGerman : "Achtung! "
property dialogErrorWordGerman : "Error: "
property dialogTooMuchFilesMessage01German : "Bist Du sicher, dass Du für "
property dialogTooMuchFilesMessage02German : " Prüfsummen überprüfen willst?"
property dialogTooMuchFilesYesGerman : "Na klar!"
property dialogTooMuchFilesNoGerman : "Bloss nicht!"
property dialogNothingSelectedMessageGerman : "Bitte wähle eine oder mehrere Dateien im Finder aus."
property dialogNothingSelectedButtonGerman : "Okay, mach ich!"
property dialogErrorOccurredMessageGerman : "Ein oder mehr Fehler ist aufgetreten:" & return & return
property dialogErrorOccurredButtonGerman : "Och nö!"
property dialogChecksumFileMissingMessage01German : "Die Prüfsummendatei für die Datei \""
property dialogChecksumFileMissingMessage02German : "\" fehlt oder ist fehlerhaft!"
property dialogChecksumFileMissingButtonGerman : "Mist!"
property dialogChecksumMismatchMessage01German : "Die Prüfsumme für die Datei \""
property dialogChecksumMismatchMessage02German : "\" stimmt nicht überein!"
property dialogChecksumsMatchMessageGerman : "Die Prüfsummen stimmen überein!"
property dialogChecksumsMatchButtonGerman : "Prima!"
#property dialogChecksumMismatchButtonGerman : "Gee!"

(* UnMain() *)
on run (argv)
(* Init *)
set logMessage to ""
if (my systemLanguage() is "de") then
set dialogAttentionWord to dialogAttentionWordGerman
set dialogErrorWord to dialogErrorWordGerman
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01German
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02German
set dialogTooMuchFilesYes to dialogTooMuchFilesYesGerman
set dialogTooMuchFilesNo to dialogTooMuchFilesNoGerman
set dialogNothingSelectedMessage to dialogNothingSelectedMessageGerman
set dialogNothingSelectedButton to dialogNothingSelectedButtonGerman
set dialogErrorOccurredMessage to dialogErrorOccurredMessageGerman
set dialogErrorOccurredButton to dialogErrorOccurredButtonGerman
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage01German
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage02German
set dialogChecksumFileMissingButton to dialogChecksumFileMissingButtonGerman
set dialogChecksumMismatchMessage01 to dialogChecksumMismatchMessage01German
set dialogChecksumMismatchMessage02 to dialogChecksumMismatchMessage02German
set dialogChecksumsMatchMessage to dialogChecksumsMatchMessageGerman
set dialogChecksumsMatchButton to dialogChecksumsMatchButtonGerman
else
set dialogAttentionWord to dialogAttentionWordEnglish
set dialogErrorWord to dialogErrorWordEnglish
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01English
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02English
set dialogTooMuchFilesYes to dialogTooMuchFilesYesEnglish
set dialogTooMuchFilesNo to dialogTooMuchFilesNoEnglish
set dialogNothingSelectedMessage to dialogNothingSelectedMessageEnglish
set dialogNothingSelectedButton to dialogNothingSelectedButtonEnglish
set dialogErrorOccurredMessage to dialogErrorOccurredMessageEnglish
set dialogErrorOccurredButton to dialogErrorOccurredButtonEnglish
set dialogChecksumFileMissingMessage01 to dialogChecksumFileMissingMessage01English
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage02English
set dialogChecksumFileMissingButton to dialogChecksumFileMissingButtonEnglish
set dialogChecksumMismatchMessage01 to dialogChecksumMismatchMessage01English
set dialogChecksumMismatchMessage02 to dialogChecksumMismatchMessage02English
set dialogChecksumsMatchMessage to dialogChecksumsMatchMessageEnglish
set dialogChecksumsMatchButton to dialogChecksumsMatchButtonEnglish
end if

(* Get selected files/folders *)
tell application "Finder"
set selectedItems to selection
(* Check wether something selected *)
if ((count of selectedItems) is greater than 0) then
(* walk through items *)
repeat with oneItem in selectedItems
(* Do dry-run to determine file count *)
set fileCount to 0
tell me to checkChecksums(oneItem, true)
log "fileCount: " & fileCount
if (fileCount is greater than 23) then
(* Ask user if he's sure that's what he wants to do *)
display dialog dialogTooMuchFilesMessage01 & fileCount & dialogTooMuchFilesMessage02 buttons {dialogTooMuchFilesYes, dialogTooMuchFilesNo} default button 2
set returnedButton to button returned of result
if (returnedButton is not dialogTooMuchFilesYes) then
tell me to exit repeat #quit
end if
end if
(* Now actually create the checksums *)
set fileCount to 0
tell me to checkChecksums(oneItem, false)
end repeat (* loop through sel. files *)
(* If something went wrong -> tell the user *)
if ((count of characters of logMessage) is greater than 0) then
display dialog dialogErrorOccurredMessage & logMessage buttons {dialogErrorOccurredButton} default button 1 with icon 0 (* icon 0: stop sign, icon 1: App-Icon, icon 2: Att. Sign and App Icon *)
else
display dialog dialogChecksumsMatchMessage buttons {dialogChecksumsMatchButton} default button 1
end if
else
display dialog dialogNothingSelectedMessage buttons dialogNothingSelectedButton
end if
end tell (* tell finder *)
end run

(* subroutine for checking md5 checksums *)
on checkChecksums(finderItem, dryRun)
try
(* check wether it's a file or a folder, if file create an additional md5 checksum file with similar name *)
tell application "Finder"
set theItemClass to class of finderItem
set theItemName to name of finderItem
set theItemContainer to (container of finderItem) as alias
set itemPath to POSIX path of (finderItem as alias)
set itemContainerPath to POSIX path of theItemContainer
if (theItemClass is folder) then (* not using type because it's localized, class is not *)
(* do this recursive, now with the contents of this folder *)
set aliasList to every item of finderItem (* use of "every file" would result in a list only containing the files *)
if ((count of aliasList) is greater than 0) then
repeat with oneItem in items of aliasList
tell me to createChecksums(oneItem, dryRun)
end repeat
end if
else
(* Don't check checksums of checksums! *)
if (theItemName does not end with ".md5") then
set fileCount to fileCount + 1
(* If dry-running, only increment file counter *)
if (dryRun is not true) then
(* Check for checksum file *)
set checkSum to ""
set checksumFileName to theItemName & ".md5"
set getChecksumFileContentCommand to "cd \"" & itemContainerPath & "\" && cat \"" & checksumFileName & "\""
try
tell AppleScript to set checkSum to do shell script getChecksumFileContentCommand
on error (e)
log "Error: " & e (* Probably the md5 file is missing or has a fucked-up name *)
end try
log "checksum from .md5-file: " & checkSum
(* Is the read checksum valid? *)
if (length of checkSum is less than 5) then
set logMessage to logMessage & dialogChecksumFileMissingMessage01 & checksumFileName & dialogChecksumFileMissingMessage02 & return
else
(* Create checksum for file *)
set cmd to "cd \"" & itemContainerPath & "\" && md5 -q \"" & theItemName & "\" | head -1"
# log "Creating md5 checksum with this command: " & cmd
tell AppleScript to set theItemsChecksum to do shell script cmd
log "checksum from file: " & theItemsChecksum
(* Compare checksum *)
if (theItemsChecksum is not equal to checkSum) then
set logMessage to logMessage & dialogAttentionWord & dialogChecksumMismatchMessage01 & theItemName & dialogChecksumMismatchMessage02 & " (" & theItemsChecksum & "/" & checkSum & ")" & return & return
log "Checksum does not match: " & theItemName
end if
end if
end if (* if dryRun *)
end if (* if not md5 checksum file *)
end if (* if file *)
end tell (* tell finder *)
on error (e)
set logMessage to logMessage & "Error: " & e & return
end try
end checkChecksums

on systemLanguage()
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"

try
tell AppleScript to set languageCode to do shell script cmd
on error (e)
log "WTF? Cannot determine language code."
end try

if (languageCode is "de") then
log "Deutsch"
else if (languageCode is "en") then
log "English"
else
log "WTF?"
end if

return languageCode
end systemLanguage





































































































(* nothing here *)

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Files/Create Checksum File.scpt

(* Script to create an md5 checksum file at the same location as the checksummed file

ToDo:

- escape quotes in filenames, because that will result in an error
- do the fileCount over all, not only every one selected file (multiple dialogs)
- optional crc using "cksum" instead of md5 (cksum only on Snow Leopard (10.6) and maybe higher)

*)

(* Global Vars *)
global fileCount, logMessage

(* Properties (English) *)
property dialogTooMuchFilesMessage01English : "Are you sure you want to create "
property dialogTooMuchFilesMessage02English : " checksum files?"
property dialogTooMuchFilesYesEnglish : "Yes, sure!"
property dialogTooMuchFilesNoEnglish : "Hell, no!"
property dialogNothingSelectedMessageEnglish : "Please select one or more files in Finder."
property dialogNothingSelectedButtonEnglish : "Allright, I do whatever you say!"
property dialogErrorOccurredMessageEnglish : "One or more errors occured: "
property dialogErrorOccurredButtonEnglish : "Doh!"
(* Properties (Deutsch) *)
property dialogTooMuchFilesMessage01German : "Bist Du sicher, dass Du "
property dialogTooMuchFilesMessage02German : " Prüfsummen-Dateien erzeugen willst?"
property dialogTooMuchFilesYesGerman : "Na klar!"
property dialogTooMuchFilesNoGerman : "Bloss nicht!"
property dialogNothingSelectedMessageGerman : "Bitte wähle eine oder mehrere Dateien im Finder aus."
property dialogNothingSelectedButtonGerman : "Okay, mach ich!"
property dialogErrorOccurredMessageGerman : "Ein oder mehr Fehler ist aufgetreten: "
property dialogErrorOccurredButtonGerman : "Och nö!"

(* UnMain() *)
on run (argv)
(* Init *)
set logMessage to ""
if (my systemLanguage() is "de") then
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01German
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02German
set dialogTooMuchFilesYes to dialogTooMuchFilesYesGerman
set dialogTooMuchFilesNo to dialogTooMuchFilesNoGerman
set dialogNothingSelectedMessage to dialogNothingSelectedMessageGerman
set dialogNothingSelectedButton to dialogNothingSelectedButtonGerman
set dialogErrorOccurredMessage to dialogErrorOccurredMessageGerman
set dialogErrorOccurredButton to dialogErrorOccurredButtonGerman
else
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01English
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02English
set dialogTooMuchFilesYes to dialogTooMuchFilesYesEnglish
set dialogTooMuchFilesNo to dialogTooMuchFilesNoEnglish
set dialogNothingSelectedMessage to dialogNothingSelectedMessageEnglish
set dialogNothingSelectedButton to dialogNothingSelectedButtonEnglish
set dialogErrorOccurredMessage to dialogErrorOccurredMessageEnglish
set dialogErrorOccurredButton to dialogErrorOccurredButtonEnglish
end if

(* Get selected files/folders *)
tell application "Finder"
set selectedItems to selection
(* Check wether something selected *)
if ((count of selectedItems) is greater than 0) then
(* walk through items *)
repeat with oneItem in selectedItems
(* Do dry-run to determine file count *)
set fileCount to 0
tell me to createChecksums(oneItem, true)
log "fileCount: " & fileCount
if (fileCount is greater than 23) then
(* Ask user if he's sure that's what he wants to do *)
display dialog dialogTooMuchFilesMessage01 & fileCount & dialogTooMuchFilesMessage02 buttons {dialogTooMuchFilesYes, dialogTooMuchFilesNo} default button 2
set returnedButton to button returned of result
if (returnedButton is not dialogTooMuchFilesYes) then
tell me to exit repeat #quit
end if
end if
(* Now actually create the checksums *)
set fileCount to 0
tell me to createChecksums(oneItem, false)
end repeat (* loop through sel. files *)
(* If something went wrong -> tell the user *)
if ((count of characters of logMessage) is greater than 0) then
display dialog dialogErrorOccurredMessage & logMessage buttons {dialogErrorOccurredButton} default button 1
end if
else
display dialog dialogNothingSelectedMessage buttons dialogNothingSelectedButton
end if
end tell (* tell finder *)
end run

(* subroutine for creating md5 checksums *)
on createChecksums(finderItem, dryRun)
try
(* check wether it's a file or a folder, if file create an additional md5 checksum file with similar name *)
tell application "Finder"
set theItemClass to class of finderItem
set theItemName to name of finderItem
set theItemContainer to (container of finderItem) as alias
set itemPath to POSIX path of (finderItem as alias)
set itemContainerPath to POSIX path of theItemContainer
if (theItemClass is folder) then (* not using type because it's localized, class is not *)
(* do this recursive, now with the contents of this folder *)
set aliasList to every item of finderItem (* use of "every file" would result in a list only containing the files *)
if ((count of aliasList) is greater than 0) then
repeat with oneItem in items of aliasList
tell me to createChecksums(oneItem, dryRun)
end repeat
end if
else
(* Don't create checksums of checksums! *)
if (theItemName does not end with ".md5") then
set fileCount to fileCount + 1
(* If dry-running, only increment file counter *)
if (dryRun is not true) then
(* create checksum for file *)
set checksumFileName to theItemName & ".md5"
set cmd to "cd \"" & itemContainerPath & "\" && md5 -q \"" & theItemName & "\" | head -1 > \"" & checksumFileName & "\""
log "Creating md5 checksum with this command: " & cmd
try
tell AppleScript to set cmdRes to do shell script cmd
on error (e)
log "This error occured while creating the checksum file: " & e
end try
log "Creating checksum returned: " & cmdRes
end if (* if dryRun *)
end if
end if (* if file *)
end tell (* tell finder *)
on error (e)
set logMessage to logMessage & "Error: " & e & return
end try
end createChecksums

on systemLanguage()
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"

try
tell AppleScript to set languageCode to do shell script cmd
on error (e)
log "WTF? Cannot determine language code."
end try

if (languageCode is "de") then
log "Deutsch"
else if (languageCode is "en") then
log "English"
else
log "WTF?"
end if

return languageCode
end systemLanguage





































































































(* nothing here *)

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Files/File Merge.scpt

(*

File Merge.scpt

(c) by Heiko Kretschmer

This Script merges some files into one big file, probably because you split them with "File Split.scpt"?

This Script is free of charge. Use it as you wish. Don't blame me if you or the script screws up.
As usual, feel free to use the code for your own projects.

*)
property pBadSelectionMessage : "Please select more than one files in Finder."
property pBadSelectionButton : "Allright, I do whatever you say!"
property pErrorMessage : "Something went wrong:"
property pErrorButton : "Duh!"

(* Unmain (http://mindprod.com/jgloss/unmain.html) :-) *)
on run (argv)
(* Tell finder to get me the selected files or folders *)
try
tell application "Finder"
activate
set selectedItems to selection
(* Only accept more than one selected file *)
if ((count of selectedItems) is greater than 1) then
(* Check if only files were selected, hopefully only files of one folder... *)
set theItemsContainer to (container of first item of selectedItems) as alias
set theItemsContainerPath to POSIX path of theItemsContainer
set selectionContainsOnlyFiles to true
repeat with theItem in selectedItems
set theItemClass to class of theItem (* not using 'type' because it's localized, 'class' is not *)
if (theItemClass is folder) then
(* Won't process folders *)
set selectionContainsOnlyFiles to false
end if
end repeat
if selectionContainsOnlyFiles is true then

(* Convert from file-list to string-list and add quotes *)
set filenameList to {}
repeat with oneFile in selectedItems
set filenameList to filenameList & ("\"" & name of oneFile & "\"")
end repeat

(* Since we can't be sure the files are in correct order, sort them! *)
tell me to set sortedList to quickSort(filenameList)

(* Convert list of strings to one string *)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set sortedListString to sortedList as string
set AppleScript's text item delimiters to oldDelim
log sortedListString

(* Guess the original file name *)
tell me to set mergedFileName to cut(first item in sortedList, ".Part_", 1) & "\""

(* Concatenate files *)
set cmd to "cd \"" & theItemsContainerPath & "\" && test ! -f " & mergedFileName & " && cat " & sortedListString & " > " & mergedFileName
log cmd
do shell script cmd

else
display dialog pBadSelectionMessage buttons pBadSelectionButton
end if
else
display dialog pBadSelectionMessage buttons pBadSelectionButton
end if
end tell
on error (e)
tell application "Finder"
activate
display dialog pErrorMessage & return & return & e buttons pErrorButton with icon 2
end tell
end try
end run

(* log cut("foo:bar:gaga", ":", 1) *)
to cut(str, delim, field)
set oldAST to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set elements to text items of str
set AppleScript's text item delimiters to oldAST
set res to item field of elements
return res
end cut

to quickSort(theList) (* found at http://macscripter.net/viewtopic.php?id=24766 *)
--public routine, called from your script
script bs
property alist : theList

on Qsort(leftIndex, rightIndex)
--private routine called by quickSort.
--do not call from your script!
if rightIndex > leftIndex then
set pivot to ((rightIndex - leftIndex) div 2) + leftIndex
set newPivot to Qpartition(leftIndex, rightIndex, pivot)
set theList to Qsort(leftIndex, newPivot - 1)
set theList to Qsort(newPivot + 1, rightIndex)
end if

end Qsort

on Qpartition(leftIndex, rightIndex, pivot)
--private routine called by quickSort.
--do not call from your script!
set pivotValue to item pivot of bs's alist
set temp to item pivot of bs's alist
set item pivot of bs's alist to item rightIndex of bs's alist
set item rightIndex of bs's alist to temp
set tempIndex to leftIndex
repeat with pointer from leftIndex to (rightIndex - 1)
if item pointer of bs's alist ≤ pivotValue then
set temp to item pointer of bs's alist
set item pointer of bs's alist to item tempIndex of bs's alist
set item tempIndex of bs's alist to temp
set tempIndex to tempIndex + 1
end if
end repeat
set temp to item rightIndex of bs's alist
set item rightIndex of bs's alist to item tempIndex of bs's alist
set item tempIndex of bs's alist to temp

return tempIndex
end Qpartition

end script

if length of bs's alist > 1 then bs's Qsort(1, length of bs's alist)
return bs's alist
end quickSort

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Files/File Split.scpt

(*

File Split.scpt

(c) by Heiko Kretschmer

This Script splits one big file in some smaller ones. Uses "split" as known in various Unixes and Linuxes.

This Script is free of charge. Use it as you wish. Don't blame me if you or the script screws up.
As usual, feel free to use the code for your own projects.

*)
property pBadSelectionMessage : "Please select (only) one file in Finder."
property pBadSelectionButton : "Allright, I do whatever you say!"
property pChooseSizeMessage : "Please choose a maxium file size for"
property pChooseSizeButton : "Select"
property pErrorMessage : "Something went wrong:"
property pErrorButton : "Duh!"

(* Unmain (http://mindprod.com/jgloss/unmain.html) :-) *)
on run (argv)
(* Tell finder to get me the selected files or folders *)
try
tell application "Finder"
activate
set selectedItems to selection
(* Only accept one selected file *)
if ((count of selectedItems) is 1) then
set theItem to first item in selectedItems
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 *)
(* Won't process folders *)
display dialog pBadSelectionMessage buttons pBadSelectionButton
# set l to length of itemPath
# set itemPath to text 1 thru (l - 1) of itemPath
# log "shortened: " & itemPath
else
(* X' user for file size, see See http://macscripter.net/viewtopic.php?id=10988 *)
set sizesList to {"1MB", "10MB", "100MB", "500MB", "1000MB"}
choose from list sizesList with prompt pChooseSizeMessage & " \"" & theItemName & " \":"
if (result as string is not "false") then (* result is either false or the selected listitem as string *)
(* Translate from readable to 'split'-usable sizes *)
set listchoice to result as text
#tell me to set maxSize to removeTrailingCharacters(listchoice, 1)
tell me to set maxSize to changeString of listchoice from "MB" to "m"
(* Process file *)
set cmd to "cd \"" & itemContainerPath & "\" && split -b " & maxSize & " \"" & theItemName & "\"" & " \"" & theItemName & ".Part_\""
log cmd
do shell script cmd
end if
end if
else
display dialog pBadSelectionMessage buttons pBadSelectionButton
end if
end tell
on error (e)
tell application "Finder"
activate
display dialog pErrorMessage & return & return & e buttons pErrorButton with icon 2
end tell
end try
end run

to removeTrailingCharacters(theItem, num)
if the length of theItem > 0 then
# if (the character 1 of theItem is " ") then set theItem to characters 2 thru end of theItem as string
log (length of theItem)
set theItem to characters 1 thru ((length of theItem) - num) of theItem as string
end if
return theItem
end removeTrailingCharacters

to removeTrailingSpaces(theItem)
if the length of theItem > 0 then
# if (the character 1 of theItem is " ") then set theItem to characters 2 thru end of theItem as string
log (length of theItem)
if (the last character of theItem is " ") then
set theItem to characters 1 thru ((length of theItem) - 1) of theItem as string
end if
end if
end removeTrailingSpaces

to changeString 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 changeString

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/InDesign/Copy Image.scpt

(* Tool für Sabbelbiene, läuft sicher mit ID CS3 und 4, 5 muesste man mal noch testen... *)

(* Global Vars *)
global dialogNoDocumentErrorMessage, dialogNoDocumentErrorButton


(* Properties (English) *)
property dialogNoDocumentErrorMessageEN : "No document opened. Please do so."
property dialogNoDocumentErrorButtonEN : "OK"
property dialogNotOneFilledAndAtLeastOneEmptyErrorMessageEN : "I need at least two image boxes, one with an image loaded, and one empty."
property dialogNotOneFilledAndAtLeastOneEmptyErrorButtonEN : "Okay…"
property dialogNotOnlyImageBoxesSelectedMessageEN : "There are not only *image*-boxes selected. You might want to do so."
property dialogNotOnlyImageBoxesSelectedButtonEN : "Duh!"
property dialogLessThanTwoBoxesSelectedMessageEN : "There are less than two boxes selected. Must be at least two."
property dialogLessThanTwoBoxesSelectedButtonEN : "I see…"
property dialogCouldNotPlaceImageMessage01EN : "Unable to load this file: "
property dialogCouldNotPlaceImageMessage02EN : "Maybe it's not existing (anymore)?"
property dialogCouldNotPlaceImageButtonEN : "I'll check it!"

(* Properties (Deutsch) *)
property dialogNoDocumentErrorMessageDE : "Kein Fenschter offen. Mach eines auf!"
property dialogNoDocumentErrorButtonDE : "OK"
property dialogNotOneFilledAndAtLeastOneEmptyErrorMessageDE : "Ich brauche mindestens zwei Bildrahmen: Einer mit nem Bild drin, einer leer."
property dialogNotOneFilledAndAtLeastOneEmptyErrorButtonDE : "Okay…"
property dialogNotOnlyImageBoxesSelectedMessageDE : "Es sind nicht nur *Bild*rahmen ausgewaehlt. Mach das mal!"
property dialogNotOnlyImageBoxesSelectedButtonDE : "Ach so…"
property dialogLessThanTwoBoxesSelectedMessageDE : "Es sind weniger als zwei Rahmen ausgewaehlt. Mach das mal!"
property dialogLessThanTwoBoxesSelectedButtonDE : "Wenns sein muss…"
property dialogCouldNotPlaceImageMessage01DE : "Konnte die Datei nicht laden: "
property dialogCouldNotPlaceImageMessage02DE : "Vielleicht gibts die nicht (mehr)?"
property dialogCouldNotPlaceImageButtonDE : "Ich prüfe das!"

(* main :-) *)
on run (argv)

(* Localization *)
if (my systemLanguage() is "de") then
set dialogNoDocumentErrorMessage to dialogNoDocumentErrorMessageDE
set dialogNoDocumentErrorButton to dialogNoDocumentErrorButtonDE
set dialogNotOneFilledAndAtLeastOneEmptyErrorMessage to dialogNotOneFilledAndAtLeastOneEmptyErrorMessageDE
set dialogNotOneFilledAndAtLeastOneEmptyErrorButton to dialogNotOneFilledAndAtLeastOneEmptyErrorButtonDE
set dialogNotOnlyImageBoxesSelectedMessage to dialogNotOnlyImageBoxesSelectedMessageDE
set dialogNotOnlyImageBoxesSelectedButton to dialogNotOnlyImageBoxesSelectedButtonDE
set dialogLessThanTwoBoxesSelectedMessage to dialogLessThanTwoBoxesSelectedMessageDE
set dialogLessThanTwoBoxesSelectedButton to dialogLessThanTwoBoxesSelectedButtonDE
set dialogCouldNotPlaceImageMessage01 to dialogCouldNotPlaceImageMessage01DE
set dialogCouldNotPlaceImageMessage02 to dialogCouldNotPlaceImageMessage02DE
set dialogCouldNotPlaceImageButton to dialogCouldNotPlaceImageButtonDE
else
set dialogNoDocumentErrorMessage to dialogNoDocumentErrorMessageEN
set dialogNoDocumentErrorButton to dialogNoDocumentErrorButtonEN
set dialogNotOneFilledAndAtLeastOneEmptyErrorMessage to dialogNotOneFilledAndAtLeastOneEmptyErrorMessageEN
set dialogNotOneFilledAndAtLeastOneEmptyErrorButton to dialogNotOneFilledAndAtLeastOneEmptyErrorButtonEN
set dialogNotOnlyImageBoxesSelectedMessage to dialogNotOnlyImageBoxesSelectedMessageEN
set dialogNotOnlyImageBoxesSelectedButton to dialogNotOnlyImageBoxesSelectedButtonEN
set dialogLessThanTwoBoxesSelectedMessage to dialogLessThanTwoBoxesSelectedMessageEN
set dialogLessThanTwoBoxesSelectedButton to dialogLessThanTwoBoxesSelectedButtonEN
set dialogCouldNotPlaceImageMessage01 to dialogCouldNotPlaceImageMessage01EN
set dialogCouldNotPlaceImageMessage02 to dialogCouldNotPlaceImageMessage02EN
set dialogCouldNotPlaceImageButton to dialogCouldNotPlaceImageButtonEN
end if

(* Sags dem InDesign *)
tell application "Adobe InDesign CS3"
(* Settings *)
set Zeitlupe to 0.0 # Fuers delay :-)

(* Hols in den Vordergrund *)
activate
-- Guck mal, ob mindestens ein Dokument offen ist
set docs to documents
if (count of docs) is less than 1 then
(* Megger *)
display dialog dialogNoDocumentErrorMessage buttons {dialogNoDocumentErrorButton}
return
else
(* Ois isi *)
set doc to document 1

(* Hole alle selektierten Elemente *)
set sel to selection

(* Checken, ob es genau zwei sind *)
if (count of sel) ≥ 2 then

(* Sind die zwei selektierten Elemente eigentlich Bildrahmen? *)
set rectsAreGraphics to true
set rectsWithImages to {}
set rectsWithoutImages to {}
repeat with onePageItem in sel
(* Checken, ob das alles Bildrahmen sind *)
if content type of onePageItem is not graphic type then
set rectsAreGraphics to false
else
(* Guck mal, wieviele Bilder enthalten *)
set onePageItemsImages to images of onePageItem
if (count of onePageItemsImages) is 0 then
(* Bildrahmen enthaelt keine Bilder *)
set rectsWithoutImages to rectsWithoutImages & onePageItem
else
(* Bildrahmen enthaelt mindestens ein Bild *)
set rectsWithImages to rectsWithImages & onePageItem
end if
end if
end repeat

(* Sind alle Rahmen BILDrahmen? *)
if rectsAreGraphics then

(* Guck mal, ob eine ein Bild enthaelt und eine nix *)
# set images1 to images of item 1 of sel
# set images2 to images of second item of sel
# # if (count of images1) is 1 and (count of images2) is 0 then
if (count of rectsWithImages) is 1 and (count of rectsWithoutImages) ≥ 1 then
# (* Ordne mal die Rectangles nach Inhalt *)
# set rectWithImages to item 1 of sel
# set rectWithoutImages to item 2 of sel
# if (count of images1) < (count of images2) then
# set rectWithImages to item 2 of sel
# set rectWithoutImages to item 1 of sel
# end if

(* Kopiere das Bild und die Koordinaten der linken oberen Ecke *)
tell first item of rectsWithImages
#log (all graphics as string)
#log geometric bounds of first item of all graphics
set {ry1, rx1, ry2, rx2} to geometric bounds
tell first item of all graphics
set {gy1, gx1, gy2, gx2} to geometric bounds (* http://osdir.com/ml/applescript-users/2009-05/msg00272.html *)
log {gy1, gx1, gy2, gx2}
set yOff to gy1 - ry1
set xOff to gx1 - rx1
log "yOff: " & yOff
log "xOff: " & xOff
set ySize to gy2 - gy1
set xSize to gx2 - gx1
log "ySize: " & ySize
log "xSize: " & xSize
set filePathOfImage to file path of item link
set pFlip to flip
set pHorizontalScale to horizontal scale
set pVerticalScale to vertical scale
set pRotationAngle to rotation angle
set pShearAngle to shear angle
set pLabel to label
set pAssocXMLElement to associated XML element
set pAppliedObjectStyle to applied object style
end tell
# log filePathOfImage
end tell

(* Nun alle leeren Boxen begluecken *)
repeat with rectWithoutImages in rectsWithoutImages
(* Fuege das Bild mit den Koordinaten in die leere Box ein *)
tell rectWithoutImages
try
set myImage to place filePathOfImage
set {ry1, rx1, ry2, rx2} to geometric bounds
tell first item of all graphics
# set {gy1, gx1, gy2, gx2} to geometric bounds (* Bounds des platzierten Bildes *)
set rotation angle to pRotationAngle
delay Zeitlupe
set shear angle to pShearAngle
delay Zeitlupe
set horizontal scale to pHorizontalScale
delay Zeitlupe
set vertical scale to pVerticalScale
set flip to pFlip
set label to pLabel
#read-only! set associated XML element to pAssocXMLElement
set applied object style to pAppliedObjectStyle

(* Bounds des platzierten Bildes *)
delay Zeitlupe
set {gy1, gx1, gy2, gx2} to geometric bounds

(* Berechne die Grösse des skalierten Bildes *)
set ySize to gy2 - gy1
set xSize to gx2 - gx1
log "ySize: " & ySize
log "xSize: " & xSize

(* Zurück zum linken oberen Ende des RAHMENS, weil das Bild beim Skalieren von der Mitte des Bildes aus zentriert wurde *)
set gy1 to ry1
set gx1 to rx1
set gy2 to gy1 + ySize
set gx2 to gx1 + xSize
set geometric bounds to {gy1, gx1, gy2, gx2}
delay Zeitlupe

(* Offset innerhalb des Rahmens wie beim Original wiederherstellen *)
log {gy1, gx1, gy2, gx2}
set gy1 to gy1 + yOff
set gx1 to gx1 + xOff
set gy2 to gy2 + yOff
set gx2 to gx2 + xOff
set ySize to gy2 - gy1
set xSize to gx2 - gx1
log "ySize: " & ySize
log "xSize: " & xSize
#set gy2 to gy1 + ySize
#set gx2 to gx2 + xSize
log {gy1, gx1, gy2, gx2}
set geometric bounds to {gy1, gx1, gy2, gx2}
delay Zeitlupe
end tell (* tell first graphic *)
on error (e)
display dialog dialogCouldNotPlaceImageMessage01 & filePathOfImage & return & "(" & e & ")" & return & dialogCouldNotPlaceImageMessage02 buttons {dialogCouldNotPlaceImageButton}
end try
end tell (* tell rect w/o images *)
end repeat (* mit allen leeren rects *)
else
display dialog dialogNotOneFilledAndAtLeastOneEmptyErrorMessage buttons {dialogNotOneFilledAndAtLeastOneEmptyErrorButton}
end if (* if ein bildrahmen was drin, und einer nicht *)

else
display dialog dialogNotOnlyImageBoxesSelectedMessage buttons {dialogNotOnlyImageBoxesSelectedButton}
end if (* sind das auch Bildrahmen? *)

else
display dialog dialogLessThanTwoBoxesSelectedMessage buttons {dialogLessThanTwoBoxesSelectedButton}
end if (* if selection >= 2 *)

end if
end tell

(* When debugging *)
# tell application "AppleScript Editor" to activate


end run


# -----------------------------------------------------

on systemLanguage()
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"

try
tell AppleScript to set languageCode to do shell script cmd
on error (e)
log "WTF? Cannot determine language code."
end try

if (languageCode is "de") then
log "Deutsch"
else if (languageCode is "en") then
log "English"
else
log "WTF?"
end if

return languageCode
end systemLanguage

to complain about foo
tell AppleScript to say foo
end complain




Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/*****.scpt

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

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/****.scpt

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

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/***.scpt

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

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/**.scpt

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

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/*.scpt

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

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Google Album Artwork Of Current Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Google Lyrics Of Current Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Open Current Track's Lyrics in TextEdit.scpt

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Paste Current iTunes Track with Album.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Paste Current iTunes Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Show Current Track's Whole Album in Library.scpt

# 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Speak Current Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Volume/Decrease (-) Volume.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Volume/Increase (+) Volume.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Volume/Mute Volume.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Currently Playing Track/Volume/Toggle Mute.scpt

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/*****.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/****.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/***.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/**.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/*.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Google Album Artwork Of Selected Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Google Lyrics Of Selected Track.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Paste Selected iTunes Tracks with Album.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Paste Selected iTunes Tracks.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Play Single Track.scpt

(* 
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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/iTunes Selected Tracks/Remove Leading "01" from Title.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Mail/Copy Selected Mail To Clipboard.scpt

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Mail/Reply Mail With Quote (buggy).scpt

(* 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


Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Mail/Save Selected Mails As RTF_buggy.scpt

(* Script saves selected mails als RTF in an chosen folder *)


tell application "Mail"

set selectedMessages to selection

if (count selectedMessages) is greater than 0 then

(* let user choose a folder to save the messages *)
tell application "Finder"
activate
try
set chosenFolder to choose folder with prompt "Please select folder to save messages in:"
log chosenFolder
tell application "Mail"
activate
repeat with oneMessage in selectedMessages

tell oneMessage
# -GEHT NICHT- log all headers
# 1GEHT! set t to all headers
# 1GEHT! log t
set oneMessageDateReceived to date received
tell me to set oneMessageDate to timestampWithDate(oneMessageDateReceived)
if (length of oneMessageDate is 0) then
set oneMessageDateSent to date sent
tell me to set oneMessageDate to timestampWithDate(oneMessageDateSent)
end if
set oneMessageFileName to oneMessageDate & "_" & subject & ".rtf" #& "_" & sender
log oneMessageFileName



end tell (* Message of Mail *)
# save message oneMessage in chosenFolder & ":" & oneMessageFileName #as "rtf"
save oneMessage in chosenFolder & ":" & oneMessageFileName #as "rtf"
-- HIER BUGGTS! ---^


end repeat
end tell (* Mail *)
on error (e)
log "Error: " & e
end try
end tell (* Finder *)

end if (* If something selected *)

end tell (* Mail *)








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

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Mail/Save Selected Messages As Text.scpt

#tell application "Finder" to set ptd to (path to desktop folder) as string

tell application "Mail"
set theMessages to selection
if ((count of theMessages) > 0) then
try
tell application "Finder"
set chosenFolder to choose folder with prompt "Choose folder to save messages in:"
end tell (* Finder *)

(* Save the messages *)
repeat with theMessage in theMessages
--mailbody set theText to content of theMessage
set theText to source of theMessage -- raw message (header & body)
tell theMessage
set theMessageSubject to subject
set theMessageDateReceived to date received
set theMessageDateSent to date sent
#if (
tell me to set theMessageDate to timestamp(theMessageDateReceived)
set theFileName to "Foo.txt"
set theFileName to theMessageDate & "_" & theMessageSubject & ".txt"
#set theFileName to theMessageDate & ".txt"
end tell (* theMessage *)

(* this whole blocks throws errors in every command! although it works fine. *)
tell application "Finder"
set theFile to (chosenFolder as string) & theFileName #"Message Number " & (theMessage's id as string)
set theFileID to open for access file theFile with write permission
write theText to theFileID
try
close access theFileID # throws -10004 - WHY?
on error (e)
log "Error: " & e
end try
end tell
end repeat

on error (e)
log "Error: " & e
end try

end if
end tell (* Mail *)





(* get a time stamp *)
on timestamp(givenDate)
set dateYear to year of givenDate
set dateMonth to addLeadingZeros(2, (month of givenDate as number))
set dateDay to addLeadingZeros(2, day of givenDate)
set dateHour to addLeadingZeros(2, hours of givenDate)
set dateMinute to addLeadingZeros(2, minutes of givenDate)
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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Searches/Google Images Selected Text.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Searches/Google Selected Text.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Searches/Leo Selected Text.scpt

on run (argv)

(* Save old Clipboard Contents *)
set oldClipboard to the clipboard

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
tell application "System Events" to keystroke "c" using {command down}
get clipboard info
log (the clipboard)

(* Get the Clipboard *)
set someword to the clipboard
log "someWord: " & someword
#return
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

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

(* Restore previous clipboard *)
set the clipboard to oldClipboard
end run

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Searches/Look Up Selected Text In Dictionary.scpt

(* 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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/Kenny.scpt

on run (argv)
#log kennify("Gaga")

(* Save old Clipboard Contents *)
my logToConsole("getting old clipboard contents...")
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""
my logToConsole("emptied the clipboard.")

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
if someword is not "" then
(* String conversion *)
tell me to set newWord to kennify(someword)
log "newWord: " & newWord
my logToConsole("newWord: " & newWord)
set the clipboard to newWord
set newClipboard to the clipboard
my logToConsole("new clipboard content: " & newClipboard)

(* Paste it *)
# delay 1 (* Essential - The cmd-v might been executed BEFORE the clipboard is actually updated! *)
tell application "System Events" to keystroke "v" using {command down}
end if

(* Clipboard restore *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! *)
set the clipboard to oldClipboard
end run


on kennify(givenString)
set kennifiedString to ""
(* Get the scripts' root path *)
set pfad to path to me (* Might not work properly in AppleScript Editor, since it does not point to the script, but to AppleScript Editor... *)
set posix_path to POSIX path of pfad
tell me to logToConsole(posix_path)
set textConversionFolderPath to my pathOfFilePath(posix_path)
tell me to logToConsole(textConversionFolderPath)
set scriptsFolderPath to my pathOfFilePath(textConversionFolderPath)
tell me to logToConsole(scriptsFolderPath)
(* Locate the helper script *)
set pathToKenny to scriptsFolderPath & "/Zome More Tools/_Internals/Kenny/kenny.pl"
(* Kennify *)
set cmd to "echo \"" & givenString & "\" | \"" & pathToKenny & "\""
try
set kennifiedString to do shell script cmd
on error (e)
log e
end try
return kennifiedString
end kennify


on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole


on pathOfFilePath(fullPath)
# http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/index.html
# http://macscripter.net/viewtopic.php?id=24525

(* Text-Liste in echte Liste umwandeln *)
set oldAST to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set elements to text items of fullPath

set elememtsminuseins to items 1 thru ((count of items in elements) - 1) of elements

set res to elememtsminuseins as text


set AppleScript's text item delimiters to oldAST

res
end pathOfFilePath

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/Lowercase.scpt

(* BTW: Error -25131 is badPasteboardIndexErr - item index does not exist
http://discussions.info.apple.com/thread.jspa?messageID=9962008
*)


(* Main *)
on run (argv)
#delay 1
my logToConsole("--")
my logFrontMostProcess()

#log my lowerCase("DOH!")

(* Save old Clipboard Contents *)
my logToConsole("getting old clipboard contents...")
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""
my logToConsole("emptied the clipboard.")

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
if someword is not "" then
(* String conversion *)
tell me to set newWord to lowerCase(someword)
log "newWord: " & newWord
my logToConsole("newWord: " & newWord)
set the clipboard to newWord
set newClipboard to the clipboard
my logToConsole("new clipboard content: " & newClipboard)

(* Paste it *)
delay 1 (* Essential - The cmd-v might been executed BEFORE the clipboard is actually updated! *)
tell application "System Events" to keystroke "v" using {command down}
end if

(* Clipboard restore *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! *)
set the clipboard to oldClipboard

my logFrontMostProcess()
end run

on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

to lowerCase(s)
log "s: " & s
log "len s: " & length of s
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase


Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/Mirror.scpt

(* Main *)
on run (argv)
my logToConsole("--")
my logFrontMostProcess()

(* Save old Clipboard Contents *)
my logToConsole("getting old clipboard contents...")
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""
my logToConsole("emptied the clipboard.")

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
if someword is not "" then
(* String conversion *)
tell me to set newWord to mirror(someword)
log "newWord: " & newWord
my logToConsole("newWord: " & newWord)
set the clipboard to newWord
set newClipboard to the clipboard
my logToConsole("new clipboard content: " & newClipboard)

(* Paste it *)
delay 1 (* Essential - The cmd-v might been executed BEFORE the clipboard is actually updated! *)
tell application "System Events" to keystroke "v" using {command down}
end if

(* Clipboard restore *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! *)
set the clipboard to oldClipboard

my logFrontMostProcess()
end run


to mirror(givenString)
set returnString to ""
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
tell me to set returnString to mirrorUsingAlphabet(givenString, uc)
tell me to set returnString to mirrorUsingAlphabet(returnString, lc)
return returnString
end mirror

on mirrorUsingAlphabet(givenString, alphabet)
set returnString to ""
considering case
(* Uppercase letters *)
repeat with oneChar in givenString
set o to offset of oneChar in alphabet
if o is not 0 then
if o > 13 then
# set p to 27 - o
set p to o - 13
log p
set q to 14 - p
log q
else
#set p to 14 - o
#log p
set q to 27 - o
log q
end if
set mirrorChar to character q in alphabet
else
set mirrorChar to oneChar
end if
set returnString to returnString & mirrorChar
log mirrorChar
#set
end repeat
(* Lowercase letters *)
# repeat with oneChar in givenString
# set o to offset of oneChar in lc
# end repeat
end considering
return returnString
end mirrorUsingAlphabet

on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess



Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROT13.scpt

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rot13(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rot5(givenString)
tell me to set result to rotXX(givenString, 5)
return result
end rot5

to rot13(givenString)
tell me to set result to rotXX(givenString, 13)
return result
end rot13

to rot5And13(givenString)
tell me to set result to rotXX(givenString, 5)
tell me to set result to rotXX(result, 13)
return result
end rot5And13

to rot18(givenString) (* I'd say http://www.rot18.com/ is wrong! Those do ROT13+ROT5 instead of ROT18! As does my monoalphabetic substitution code converter! F*CK! *)
tell me to set result to rotXX(givenString, 18)
return result
end rot18

to rot47(givenString)
tell me to set result to rotXX(givenString, 47)
return result
end rot47

to rotXX(givenString, rotFactor)
set returnString to ""
# set runs to 2
set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
if rotFactor is 47 then
set rotAlphabet to ascii33to126
# set runs to 1 (* case is automatically done by 47 *)
else
set rotAlphabet to alphabet
# set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
if rotFactor is 5 then
set rotAlphabet to (characters 27 thru (26 + rotFactor * 2) of rotAlphabet) as string
#log "rotAlphabet: " & rotAlphabet
end if
end if
# log length of ascii33to126 # http://de.wikipedia.org/wiki/ROT13
#if rotFactor is 13 then

(* Let's do this two times, on for every case :-) *)
set lowerCaseRun to false
repeat 2 times
set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
#log "FOO"
considering case

(* Walk through given string char by char *)
repeat with char in givenString
# log ""
# log "char: " & char
set p to offset of char in rotAlphabet
if (p is not 0) then
set r to (((p + rotFactor) mod (rotFactor * 2)))
if r is 0 then set r to (rotFactor * 2)
set rotChar to character r of rotAlphabet

else
(* Case didn't match *)
set rotChar to char
end if
# log "rotChar: " & rotChar
set returnString to returnString & rotChar
end repeat

end considering

(* start over, but this time lowercase :-) Weird solution! :-) *)
if rotFactor is not 47 and rotFactor is not 5 and not lowerCaseRun then
tell me to set rotAlphabet to lowerCase(rotAlphabet)
set givenString to returnString
set returnString to ""
set lowerCaseRun to true
if rotFactor is 18 then
set rotFactor to 13 (* don't translate numbers AGAIN! (Just do the letters, cut the numbers *)
end if
else (* ROT 47 and ROT 5 don't have cases, so we need only one run *)
exit repeat
end if

end repeat

return returnString
end rotXX

to changeString 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 changeString

to lowerCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase
on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROT18.scpt

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rot18(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rot5(givenString)
tell me to set result to rotXX(givenString, 5)
return result
end rot5

to rot13(givenString)
tell me to set result to rotXX(givenString, 13)
return result
end rot13

to rot5And13(givenString)
tell me to set result to rotXX(givenString, 5)
tell me to set result to rotXX(result, 13)
return result
end rot5And13

to rot18(givenString) (* I'd say http://www.rot18.com/ is wrong! Those do ROT13+ROT5 instead of ROT18! As does my monoalphabetic substitution code converter! F*CK! *)
tell me to set result to rotXX(givenString, 18)
return result
end rot18

to rot47(givenString)
tell me to set result to rotXX(givenString, 47)
return result
end rot47

to rotXX(givenString, rotFactor)
set returnString to ""
# set runs to 2
set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
if rotFactor is 47 then
set rotAlphabet to ascii33to126
# set runs to 1 (* case is automatically done by 47 *)
else
set rotAlphabet to alphabet
# set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
if rotFactor is 5 then
set rotAlphabet to (characters 27 thru (26 + rotFactor * 2) of rotAlphabet) as string
#log "rotAlphabet: " & rotAlphabet
end if
end if
# log length of ascii33to126 # http://de.wikipedia.org/wiki/ROT13
#if rotFactor is 13 then

(* Let's do this two times, on for every case :-) *)
set lowerCaseRun to false
repeat 2 times
set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
#log "FOO"
considering case

(* Walk through given string char by char *)
repeat with char in givenString
# log ""
# log "char: " & char
set p to offset of char in rotAlphabet
if (p is not 0) then
set r to (((p + rotFactor) mod (rotFactor * 2)))
if r is 0 then set r to (rotFactor * 2)
set rotChar to character r of rotAlphabet

else
(* Case didn't match *)
set rotChar to char
end if
# log "rotChar: " & rotChar
set returnString to returnString & rotChar
end repeat

end considering

(* start over, but this time lowercase :-) Weird solution! :-) *)
if rotFactor is not 47 and rotFactor is not 5 and not lowerCaseRun then
tell me to set rotAlphabet to lowerCase(rotAlphabet)
set givenString to returnString
set returnString to ""
set lowerCaseRun to true
if rotFactor is 18 then
set rotFactor to 13 (* don't translate numbers AGAIN! (Just do the letters, cut the numbers *)
end if
else (* ROT 47 and ROT 5 don't have cases, so we need only one run *)
exit repeat
end if

end repeat

return returnString
end rotXX

to changeString 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 changeString

to lowerCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase
on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROT47.scpt

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rot47(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rot5(givenString)
tell me to set result to rotXX(givenString, 5)
return result
end rot5

to rot13(givenString)
tell me to set result to rotXX(givenString, 13)
return result
end rot13

to rot5And13(givenString)
tell me to set result to rotXX(givenString, 5)
tell me to set result to rotXX(result, 13)
return result
end rot5And13

to rot18(givenString) (* I'd say http://www.rot18.com/ is wrong! Those do ROT13+ROT5 instead of ROT18! As does my monoalphabetic substitution code converter! F*CK! *)
tell me to set result to rotXX(givenString, 18)
return result
end rot18

to rot47(givenString)
tell me to set result to rotXX(givenString, 47)
return result
end rot47

to rotXX(givenString, rotFactor)
set returnString to ""
# set runs to 2
set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
if rotFactor is 47 then
set rotAlphabet to ascii33to126
# set runs to 1 (* case is automatically done by 47 *)
else
set rotAlphabet to alphabet
# set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
if rotFactor is 5 then
set rotAlphabet to (characters 27 thru (26 + rotFactor * 2) of rotAlphabet) as string
#log "rotAlphabet: " & rotAlphabet
end if
end if
# log length of ascii33to126 # http://de.wikipedia.org/wiki/ROT13
#if rotFactor is 13 then

(* Let's do this two times, on for every case :-) *)
set lowerCaseRun to false
repeat 2 times
set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
#log "FOO"
considering case

(* Walk through given string char by char *)
repeat with char in givenString
# log ""
# log "char: " & char
set p to offset of char in rotAlphabet
if (p is not 0) then
set r to (((p + rotFactor) mod (rotFactor * 2)))
if r is 0 then set r to (rotFactor * 2)
set rotChar to character r of rotAlphabet

else
(* Case didn't match *)
set rotChar to char
end if
# log "rotChar: " & rotChar
set returnString to returnString & rotChar
end repeat

end considering

(* start over, but this time lowercase :-) Weird solution! :-) *)
if rotFactor is not 47 and rotFactor is not 5 and not lowerCaseRun then
tell me to set rotAlphabet to lowerCase(rotAlphabet)
set givenString to returnString
set returnString to ""
set lowerCaseRun to true
if rotFactor is 18 then
set rotFactor to 13 (* don't translate numbers AGAIN! (Just do the letters, cut the numbers *)
end if
else (* ROT 47 and ROT 5 don't have cases, so we need only one run *)
exit repeat
end if

end repeat

return returnString
end rotXX

to changeString 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 changeString

to lowerCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase
on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROT5+13.scpt

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rot5And13(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rot5(givenString)
tell me to set result to rotXX(givenString, 5)
return result
end rot5

to rot13(givenString)
tell me to set result to rotXX(givenString, 13)
return result
end rot13

to rot5And13(givenString)
tell me to set result to rotXX(givenString, 5)
tell me to set result to rotXX(result, 13)
return result
end rot5And13

to rot18(givenString) (* I'd say http://www.rot18.com/ is wrong! Those do ROT13+ROT5 instead of ROT18! As does my monoalphabetic substitution code converter! F*CK! *)
tell me to set result to rotXX(givenString, 18)
return result
end rot18

to rot47(givenString)
tell me to set result to rotXX(givenString, 47)
return result
end rot47

to rotXX(givenString, rotFactor)
set returnString to ""
# set runs to 2
set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
if rotFactor is 47 then
set rotAlphabet to ascii33to126
# set runs to 1 (* case is automatically done by 47 *)
else
set rotAlphabet to alphabet
# set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
if rotFactor is 5 then
set rotAlphabet to (characters 27 thru (26 + rotFactor * 2) of rotAlphabet) as string
#log "rotAlphabet: " & rotAlphabet
end if
end if
# log length of ascii33to126 # http://de.wikipedia.org/wiki/ROT13
#if rotFactor is 13 then

(* Let's do this two times, on for every case :-) *)
set lowerCaseRun to false
repeat 2 times
set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
#log "FOO"
considering case

(* Walk through given string char by char *)
repeat with char in givenString
# log ""
# log "char: " & char
set p to offset of char in rotAlphabet
if (p is not 0) then
set r to (((p + rotFactor) mod (rotFactor * 2)))
if r is 0 then set r to (rotFactor * 2)
set rotChar to character r of rotAlphabet

else
(* Case didn't match *)
set rotChar to char
end if
# log "rotChar: " & rotChar
set returnString to returnString & rotChar
end repeat

end considering

(* start over, but this time lowercase :-) Weird solution! :-) *)
if rotFactor is not 47 and rotFactor is not 5 and not lowerCaseRun then
tell me to set rotAlphabet to lowerCase(rotAlphabet)
set givenString to returnString
set returnString to ""
set lowerCaseRun to true
if rotFactor is 18 then
set rotFactor to 13 (* don't translate numbers AGAIN! (Just do the letters, cut the numbers *)
end if
else (* ROT 47 and ROT 5 don't have cases, so we need only one run *)
exit repeat
end if

end repeat

return returnString
end rotXX

to changeString 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 changeString

to lowerCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase
on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROT5.scpt

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rot5(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rot5(givenString)
tell me to set result to rotXX(givenString, 5)
return result
end rot5

to rot13(givenString)
tell me to set result to rotXX(givenString, 13)
return result
end rot13

to rot5And13(givenString)
tell me to set result to rotXX(givenString, 5)
tell me to set result to rotXX(result, 13)
return result
end rot5And13

to rot18(givenString) (* I'd say http://www.rot18.com/ is wrong! Those do ROT13+ROT5 instead of ROT18! As does my monoalphabetic substitution code converter! F*CK! *)
tell me to set result to rotXX(givenString, 18)
return result
end rot18

to rot47(givenString)
tell me to set result to rotXX(givenString, 47)
return result
end rot47

to rotXX(givenString, rotFactor)
set returnString to ""
# set runs to 2
set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
if rotFactor is 47 then
set rotAlphabet to ascii33to126
# set runs to 1 (* case is automatically done by 47 *)
else
set rotAlphabet to alphabet
# set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
if rotFactor is 5 then
set rotAlphabet to (characters 27 thru (26 + rotFactor * 2) of rotAlphabet) as string
#log "rotAlphabet: " & rotAlphabet
end if
end if
# log length of ascii33to126 # http://de.wikipedia.org/wiki/ROT13
#if rotFactor is 13 then

(* Let's do this two times, on for every case :-) *)
set lowerCaseRun to false
repeat 2 times
set rotAlphabet to (characters 1 thru (rotFactor * 2) of rotAlphabet) as string
#log "FOO"
considering case

(* Walk through given string char by char *)
repeat with char in givenString
# log ""
# log "char: " & char
set p to offset of char in rotAlphabet
if (p is not 0) then
set r to (((p + rotFactor) mod (rotFactor * 2)))
if r is 0 then set r to (rotFactor * 2)
set rotChar to character r of rotAlphabet

else
(* Case didn't match *)
set rotChar to char
end if
# log "rotChar: " & rotChar
set returnString to returnString & rotChar
end repeat

end considering

(* start over, but this time lowercase :-) Weird solution! :-) *)
if rotFactor is not 47 and rotFactor is not 5 and not lowerCaseRun then
tell me to set rotAlphabet to lowerCase(rotAlphabet)
set givenString to returnString
set returnString to ""
set lowerCaseRun to true
if rotFactor is 18 then
set rotFactor to 13 (* don't translate numbers AGAIN! (Just do the letters, cut the numbers *)
end if
else (* ROT 47 and ROT 5 don't have cases, so we need only one run *)
exit repeat
end if

end repeat

return returnString
end rotXX

to changeString 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 changeString

to lowerCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of uc
set s to text items of s
set AppleScript's text item delimiters to character i of lc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end lowerCase
on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/ROTrandom.scpt

(* This is a practical joke, back in the old times we used this encoding to make sure, no one ever decodes it :-) *)

(* Main *)
on run (argv)
(* Save previous clipboard contents *)
set oldClipboard to the clipboard
try
my logToConsole("oldClipboard: " & oldClipboard)
on error (e)
my logToConsole("oldClipboard: was not loggable, maybe not TEXT?")
end try

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
my logToConsole("someword: " & someword)
if someword is not "" then
(* Translate text *)
tell me to set someword to rotRandom(someword)
set the clipboard to someword

(* Paste the translated text *)
tell application "System Events" to keystroke "v" using {command down}
#delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)
end if

(* Restore previous clipboard *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! (THIS IS SERIOUS! DON'T LAUGH!) *)
set the clipboard to oldClipboard
end run


(* ******** Methods ******** *)
to rotRandom(givenString)
set returnString to ""
set ascii33to126 to "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

(* Walk through given string char by char *)
repeat with char in givenString
set randomNumber to (random number from 1 to length of ascii33to126)
set rotChar to character randomNumber of ascii33to126
set returnString to returnString & rotChar

end repeat

return returnString
end rotRandom

on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Text conversion/Uppercase.scpt

on run (argv)

#log my lowerCase("doh!")

(* Save old Clipboard Contents *)
set oldClipboard to the clipboard

(* Clear Clipboard *)
set the clipboard to ""

(* Get selected text *)
set someword to ""
repeat 23 times
(* Try to copy the selection to clipboard, might fail, if some more modifiers down (f.e. if you launch this script with FastScripts and a Shortcut that uses option, control or shift..) *)
try
tell application "System Events" to keystroke "c" using {command down}
(* Try to copy the clipboard contents *)
try
set someword to the clipboard
if (oldClipboard is not equal to someword and someword is not "") then
exit repeat
end if
on error (e)
my logToConsole("Error while copying selection to clipboard (cmd-c): " & e)
end try
on error (e)
my logToConsole("Error while copying the clipboard: " & e)
end try
delay 0.1
end repeat

(* If copying to and from clipboard worked *)
if someword is not "" then
(* String conversion *)
tell me to set newWord to upperCase(someword)
log "newWord: " & newWord
set the clipboard to newWord

(* Paste it *)
delay 1 (* Essential - The cmd-v might been executed BEFORE the clipboard is actually updated! *)
tell application "System Events" to keystroke "v" using {command down}
end if

(* Clipboard restore *)
delay 2 (* Essential - The cmd-V might not been fully executed at this time when we restore the clip! *)
set the clipboard to oldClipboard

end run

on logToConsole(someText)
tell AppleScript
try
set cmd to "logger -p daemon.notice \"" & "LHS: " & someText & "\""
do shell script cmd
on error (e)
log e
end try
end tell
end logToConsole

on logFrontMostProcess()
(* Find the frontmost process *)
tell application "System Events" to set fmps to (every process whose frontmost is true) -- and has scripting terminology is true)
set fmp to first item in fmps

(* Log name *)
my logToConsole("Frontmost Process: " & name of fmp & " (" & short name of fmp & ")")
end logFrontMostProcess

to upperCase(s)
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set lc to "abcdefghijklmnopqrstuvwxyz"
repeat with i from 1 to 26
set AppleScript's text item delimiters to character i of lc
set s to text items of s
set AppleScript's text item delimiters to character i of uc
set s to s as text
end repeat
set AppleScript's text item delimiters to ""
return s
end upperCase


Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Timestamps/Paste Log Timestamp.scpt

on run (argv)
set oldClip to the clipboard

set the clipboard to my timestamp()


tell application "System Events" to keystroke "v" using {command down}
delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)

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 addLeadingZeros(2, (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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Timestamps/Paste Timestamp.scpt

set the clipboard to my timestamp()

set oldClip to the clipboard

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

delay 1 (* delay, since the pasting could take long - even until restore... (restored clip instead of my timestamp will get pasted! *)

set the clipboard to oldClip


(* 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))
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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Zome More Tools/_Internals/dumpAppleScriptSourcecode (buggy).scpt

set cmd to "find /Users/heiko/Development/Little\\ Helpers\\ Scripts/Little\\ Helpers\\ Scripts -name \\*.scpt -type f | while read LINE; do { echo \"----------------------------------------------------------------------\"; echo \"Dumping ${LINE}\"; osadecompile \"${LINE}\" | sed s/$/\\<br\\>/\\g | sed s/^/\\ /\\g; }; done"
with timeout of 300 seconds
tell AppleScript to set res to do shell script cmd
end timeout
log res

Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Zome More Tools/Dial Selected Number.scpt

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 /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Zome More Tools/FStream/Speak Radio Station Name.scpt

tell application "FStream.app" to set foo to «event FsRwinam»
tell AppleScript to say "Current station is " & foo



Dumping /Users/heiko/Development/Little Helpers Scripts/Little Helpers Scripts/Zome More Tools/FStream/Toggle Playback.scpt

(* 0 stopped, 3 playing *)

tell application "FStream.app"
#log (status)
-- startPlaying
if («event FsRwstat») is 0 then
«event FsRwplay»
else
«event FsRwstop»
end if
end tell