Heikos Little Helpers: Difference between revisions

From Wurst-Wasser.net
Jump to navigation Jump to search
No edit summary
Line 8: Line 8:
* [[MacOS]] X 10.0 or better :-)
* [[MacOS]] X 10.0 or better :-)
* [[FastScripts]], see http://www.red-sweater.com/fastscripts/ (If you don't care for keyboard shortcuts you can also use MacOS X' built-in tech: [http://www.viddler.com/explore/anoved/videos/17/ Video showing how to enable])
* [[FastScripts]], see http://www.red-sweater.com/fastscripts/ (If you don't care for keyboard shortcuts you can also use MacOS X' built-in tech: [http://www.viddler.com/explore/anoved/videos/17/ Video showing how to enable])
=== Download ===
[[Media:HeikosLittleHelpers20100823.zip]]


=== Setup  ===
=== Setup  ===
Line 85: Line 88:
| Checks whether the checksum files exist and match, or not.
| Checks whether the checksum files exist and match, or not.
|}
|}
 
(...and much more...)
=== Download ===
[[Media:HeikosLittleHelpers20100823.zip]]


=== Sources ===
=== Sources ===
You might be interested in how that stuff works. Take a look:
You might be interested in how that stuff works. Take a look:
HeiMac:Little Helpers Scripts heiko$ ./getSourceOfAppleScripts.sh
----------------------------------------------------------------------
Dumping ./Archive Selected File or Folder.scpt
(* Script to archive selected files/folders and name them <br>
<br>
History: <br>
<br>
2009-11-12, 12.10, hk: First version is working. <br>
<br>
ToDo:<br>
<br>
-strip leading directories from archive, so that they don't get created when expanding...<br>
<br>
<br>
<br>
*)<br>
on run (argv)<br>
tell application "Finder"<br>
set selectedItems to selection<br>
if ((count of selectedItems) is 1) then<br>
# else if ((count of selectedItems) is greater than 1) then<br>
set theItem to first item in selectedItems #as alias<br>
#get class of theItem<br>
set theItemClass to class of theItem<br>
log theItemClass<br>
set theItemName to name of theItem<br>
set theItemContainer to (container of theItem) as alias<br>
set itemPath to POSIX path of (theItem as alias)<br>
set itemContainerPath to POSIX path of theItemContainer<br>
if (theItemClass is folder) then (* not using type because it's localized, class is not *)<br>
(* remove trailing "/" *)<br>
set l to length of itemPath<br>
set itemPath to text 1 thru (l - 1) of itemPath<br>
log "shortened: " & itemPath<br>
else<br>
# mach nix <br>
end if<br>
set zipFileName to theItemName & " " & my timestamp() & ".zip"<br>
#set zipFilePath to itemContainerPath & "" & theItemName & "_" & my timestamp() & ".zip"<br>
#trasht alle dirs im zip set cmd to "zip -j -r \"" & zipFilePath & "\" \"" & itemPath & "\"" # -m<br>
set cmd to "cd \"" & itemContainerPath & "\" && zip -r \"" & zipFileName & "\" \"" & theItemName & "\"" # -m<br>
# set cmd to "zip \"" & zipFilePath & "\" -x .\\* \"" & itemPath & "\""<br>
log cmd<br>
do shell script cmd<br>
else<br>
display dialog "Please select one files/folders in Finder." buttons "Allright, I do whatever you say!"<br>
end if<br>
end tell<br>
end run<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
(* get a time stamp *)<br>
on timestamp()<br>
set dateNow to current date<br>
set dateYear to year of dateNow<br>
set dateMonth to addLeadingZeros(2, (month of dateNow as number) as string)<br>
set dateDay to addLeadingZeros(2, day of dateNow)<br>
set dateHour to addLeadingZeros(2, hours of dateNow)<br>
set dateMinute to addLeadingZeros(2, minutes of dateNow)<br>
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & " " & dateHour & "-" & dateMinute) as string<br>
end timestamp<br>
<br>
(* Liefert von einer Zahl n leading zeros zurück *)<br>
on addLeadingZeros(zeroesCount, value)<br>
<br>
(* nimmt die letzten zeroesCount Stellen des Strings *)<br>
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)<br>
log "newNumber: " & newNumber<br>
<br>
return (newNumber)<br>
end addLeadingZeros<br>
<br>
<br>
----------------------------------------------------------------------
Dumping ./Compare Checksum File.scpt
(* Script to check an md5 checksum<br>
<br>
ToDo:<br>
<br>
- escape quotes in filenames, because that will result in an error<br>
- do the fileCount over all, not only every one selected folder (multiple dialogs)<br>
- optional crc using "cksum" instead of md5 (cksum only on Snow Leopard (10.6) and maybe higher)<br>
<br>
*)<br>
<br>
(* Global Vars *)<br>
global fileCount, logMessage, dialogTooMuchFilesMessage01, dialogTooMuchFilesMessage02, dialogTooMuchFilesYes, dialogTooMuchFilesNo, dialogNothingSelectedMessage, dialogNothingSelectedButton, dialogErrorOccurredMessage, dialogErrorOccurredButton, dialogChecksumFileMissingMessage01, dialogChecksumFileMissingMessage02, dialogChecksumFileMissingButton, dialogErrorWord, dialogAttentionWord, dialogChecksumMismatchMessage01, dialogChecksumMismatchMessage02<br>
<br>
<br>
(* Properties (English) *)<br>
property dialogAttentionWordEnglish : "ATTENTION! "<br>
property dialogErrorWordEnglish : "Error: "<br>
property dialogTooMuchFilesMessage01English : "Are you sure you want to check checksums for "<br>
property dialogTooMuchFilesMessage02English : " files?"<br>
property dialogTooMuchFilesYesEnglish : "Yes, sure!"<br>
property dialogTooMuchFilesNoEnglish : "Hell, no!"<br>
property dialogNothingSelectedMessageEnglish : "Please select one or more files in Finder."<br>
property dialogNothingSelectedButtonEnglish : "Allright, I do whatever you say!"<br>
property dialogErrorOccurredMessageEnglish : "One or more errors occured:" & return & return<br>
property dialogErrorOccurredButtonEnglish : "Doh!"<br>
property dialogChecksumFileMissingMessage01English : "The checksum file for the file \""<br>
property dialogChecksumFileMissingMessage02English : "\" is missing or corrupted!"<br>
property dialogChecksumFileMissingButtonEnglish : "Gee!"<br>
property dialogChecksumMismatchMessage01English : "The checksum for the file \""<br>
property dialogChecksumMismatchMessage02English : "\" does not match!"<br>
#property dialogChecksumMismatchButtonEnglish : "Gee!"<br>
(* Properties (Deutsch) *)<br>
property dialogAttentionWordGerman : "Achtung! "<br>
property dialogErrorWordGerman : "Error: "<br>
property dialogTooMuchFilesMessage01German : "Bist Du sicher, dass Du für "<br>
property dialogTooMuchFilesMessage02German : " Prüfsummen überprüfen willst?"<br>
property dialogTooMuchFilesYesGerman : "Na klar!"<br>
property dialogTooMuchFilesNoGerman : "Bloss nicht!"<br>
property dialogNothingSelectedMessageGerman : "Bitte wähle eine oder mehrere Dateien im Finder aus."<br>
property dialogNothingSelectedButtonGerman : "Okay, mach ich!"<br>
property dialogErrorOccurredMessageGerman : "Ein oder mehr Fehler ist aufgetreten:" & return & return<br>
property dialogErrorOccurredButtonGerman : "Och nö!"<br>
property dialogChecksumFileMissingMessage01German : "Die Prüfsummendatei für die Datei \""<br>
property dialogChecksumFileMissingMessage02German : "\" fehlt oder ist fehlerhaft!"<br>
property dialogChecksumFileMissingButtonGerman : "Mist!"<br>
property dialogChecksumMismatchMessage01German : "Die Prüfsumme für die Datei \""<br>
property dialogChecksumMismatchMessage02German : "\" stimmt nicht überein!"<br>
#property dialogChecksumMismatchButtonGerman : "Gee!"<br>
<br>
(* UnMain() *)<br>
on run (argv)<br>
(* Init *)<br>
set logMessage to ""<br>
if (my systemLanguage() is "de") then<br>
set dialogAttentionWord to dialogAttentionWordGerman<br>
set dialogErrorWord to dialogErrorWordGerman<br>
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01German<br>
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02German<br>
set dialogTooMuchFilesYes to dialogTooMuchFilesYesGerman<br>
set dialogTooMuchFilesNo to dialogTooMuchFilesNoGerman<br>
set dialogNothingSelectedMessage to dialogNothingSelectedMessageGerman<br>
set dialogNothingSelectedButton to dialogNothingSelectedButtonGerman<br>
set dialogErrorOccurredMessage to dialogErrorOccurredMessageGerman<br>
set dialogErrorOccurredButton to dialogErrorOccurredButtonGerman<br>
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage01German<br>
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage02German<br>
set dialogChecksumFileMissingButton to dialogChecksumFileMissingButtonGerman<br>
set dialogChecksumMismatchMessage01 to dialogChecksumMismatchMessage01German<br>
set dialogChecksumMismatchMessage02 to dialogChecksumMismatchMessage02German<br>
else<br>
set dialogAttentionWord to dialogAttentionWordEnglish<br>
set dialogErrorWord to dialogErrorWordEnglish<br>
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01English<br>
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02English<br>
set dialogTooMuchFilesYes to dialogTooMuchFilesYesEnglish<br>
set dialogTooMuchFilesNo to dialogTooMuchFilesNoEnglish<br>
set dialogNothingSelectedMessage to dialogNothingSelectedMessageEnglish<br>
set dialogNothingSelectedButton to dialogNothingSelectedButtonEnglish<br>
set dialogErrorOccurredMessage to dialogErrorOccurredMessageEnglish<br>
set dialogErrorOccurredButton to dialogErrorOccurredButtonEnglish<br>
set dialogChecksumFileMissingMessage01 to dialogChecksumFileMissingMessage01English<br>
set dialogChecksumFileMissingMessage02 to dialogChecksumFileMissingMessage02English<br>
set dialogChecksumFileMissingButton to dialogChecksumFileMissingButtonEnglish<br>
set dialogChecksumMismatchMessage01 to dialogChecksumMismatchMessage01English<br>
set dialogChecksumMismatchMessage02 to dialogChecksumMismatchMessage02English<br>
end if<br>
<br>
(* Get selected files/folders *)<br>
tell application "Finder"<br>
set selectedItems to selection<br>
(* Check wether something selected *)<br>
if ((count of selectedItems) is greater than 0) then<br>
(* walk through items *)<br>
repeat with oneItem in selectedItems<br>
(* Do dry-run to determine file count *)<br>
set fileCount to 0<br>
tell me to checkChecksums(oneItem, true)<br>
log "fileCount: " & fileCount<br>
if (fileCount is greater than 23) then<br>
(* Ask user if he's sure that's what he wants to do *)<br>
display dialog dialogTooMuchFilesMessage01 & fileCount & dialogTooMuchFilesMessage02 buttons {dialogTooMuchFilesYes, dialogTooMuchFilesNo} default button 2<br>
set returnedButton to button returned of result<br>
if (returnedButton is not dialogTooMuchFilesYes) then<br>
tell me to exit repeat #quit<br>
end if<br>
end if<br>
(* Now actually create the checksums *)<br>
set fileCount to 0<br>
tell me to checkChecksums(oneItem, false)<br>
end repeat (* loop through sel. files *)<br>
(* If something went wrong -> tell the user *)<br>
if ((count of characters of logMessage) is greater than 0) then<br>
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 *)<br>
end if<br>
else<br>
display dialog dialogNothingSelectedMessage buttons dialogNothingSelectedButton<br>
end if<br>
end tell (* tell finder *)<br>
end run<br>
<br>
(* subroutine for checking md5 checksums *)<br>
on checkChecksums(finderItem, dryRun)<br>
try<br>
(* check wether it's a file or a folder, if file create an additional md5 checksum file with similar name *)<br>
tell application "Finder"<br>
set theItemClass to class of finderItem<br>
set theItemName to name of finderItem<br>
set theItemContainer to (container of finderItem) as alias<br>
set itemPath to POSIX path of (finderItem as alias)<br>
set itemContainerPath to POSIX path of theItemContainer<br>
if (theItemClass is folder) then (* not using type because it's localized, class is not *)<br>
(* do this recursive, now with the contents of this folder *)<br>
set aliasList to every item of finderItem (* use of "every file" would result in a list only containing the files *)<br>
if ((count of aliasList) is greater than 0) then<br>
repeat with oneItem in items of aliasList<br>
tell me to createChecksums(oneItem, dryRun)<br>
end repeat<br>
end if<br>
else<br>
(* Don't check checksums of checksums! *)<br>
if (theItemName does not end with ".md5") then<br>
set fileCount to fileCount + 1<br>
(* If dry-running, only increment file counter *)<br>
if (dryRun is not true) then<br>
(* Check for checksum file *)<br>
set checkSum to ""<br>
set checksumFileName to theItemName & ".md5"<br>
set getChecksumFileContentCommand to "cd \"" & itemContainerPath & "\" && cat \"" & checksumFileName & "\""<br>
try<br>
tell AppleScript to set checkSum to do shell script getChecksumFileContentCommand<br>
on error (e)<br>
log "Error: " & e (* Probably the md5 file is missing or has a fucked-up name *)<br>
end try<br>
log "checksum from .md5-file: " & checkSum<br>
(* Is the read checksum valid? *)<br>
if (length of checkSum is less than 5) then<br>
set logMessage to logMessage & dialogChecksumFileMissingMessage01 & checksumFileName & dialogChecksumFileMissingMessage02 & return<br>
else<br>
(* Create checksum for file *)<br>
set cmd to "cd \"" & itemContainerPath & "\" && md5 -q \"" & theItemName & "\" | head -1"<br>
# log "Creating md5 checksum with this command: " & cmd<br>
tell AppleScript to set theItemsChecksum to do shell script cmd<br>
log "checksum from file: " & theItemsChecksum<br>
(* Compare checksum *)<br>
if (theItemsChecksum is not equal to checkSum) then<br>
set logMessage to logMessage & dialogAttentionWord & dialogChecksumMismatchMessage01 & theItemName & dialogChecksumMismatchMessage02 & " (" & theItemsChecksum & "/" & checkSum & ")" & return & return<br>
log "Checksum does not match: " & theItemName<br>
end if<br>
end if<br>
end if (* if dryRun *)<br>
end if (* if not md5 checksum file *)<br>
end if (* if file *)<br>
end tell (* tell finder *)<br>
on error (e)<br>
set logMessage to logMessage & "Error: " & e & return<br>
end try<br>
end checkChecksums<br>
<br>
on systemLanguage()<br>
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"<br>
<br>
try<br>
tell AppleScript to set languageCode to do shell script cmd<br>
on error (e)<br>
log "WTF? Cannot determine language code."<br>
end try<br>
<br>
if (languageCode is "de") then<br>
log "Deutsch"<br>
else if (languageCode is "en") then<br>
log "English"<br>
else<br>
log "WTF?"<br>
end if<br>
<br>
return languageCode<br>
end systemLanguage<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
(* nothing here *)<br>
----------------------------------------------------------------------
Dumping ./Copy Selected Mail To Clipboard.scpt
(* copies selected mail from apple mail to clipboard as text *)<br>
<br>
tell application "Mail"<br>
<br>
set theSelectedMessages to selection<br>
<br>
if (count theSelectedMessages) is greater than 0 then<br>
<br>
repeat with oneSelectedMessage in theSelectedMessages<br>
tell oneSelectedMessage<br>
set t to all headers<br>
set t to t & return & content<br>
log t<br>
tell application "System Events"<br>
set the clipboard to t<br>
end tell<br>
end tell<br>
end repeat<br>
<br>
else<br>
display dialog "You haven't selected any message..." buttons {"Doh!"}<br>
end if<br>
<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./Create Checksum File.scpt
(* Script to create an md5 checksum file at the same location as the checksummed file<br>
<br>
ToDo:<br>
<br>
- escape quotes in filenames, because that will result in an error<br>
- do the fileCount over all, not only every one selected file (multiple dialogs)<br>
- optional crc using "cksum" instead of md5 (cksum only on Snow Leopard (10.6) and maybe higher)<br>
<br>
*)<br>
<br>
(* Global Vars *)<br>
global fileCount, logMessage<br>
<br>
(* Properties (English) *)<br>
property dialogTooMuchFilesMessage01English : "Are you sure you want to create "<br>
property dialogTooMuchFilesMessage02English : " checksum files?"<br>
property dialogTooMuchFilesYesEnglish : "Yes, sure!"<br>
property dialogTooMuchFilesNoEnglish : "Hell, no!"<br>
property dialogNothingSelectedMessageEnglish : "Please select one or more files in Finder."<br>
property dialogNothingSelectedButtonEnglish : "Allright, I do whatever you say!"<br>
property dialogErrorOccurredMessageEnglish : "One or more errors occured: "<br>
property dialogErrorOccurredButtonEnglish : "Doh!"<br>
(* Properties (Deutsch) *)<br>
property dialogTooMuchFilesMessage01German : "Bist Du sicher, dass Du "<br>
property dialogTooMuchFilesMessage02German : " Prüfsummen-Dateien erzeugen willst?"<br>
property dialogTooMuchFilesYesGerman : "Na klar!"<br>
property dialogTooMuchFilesNoGerman : "Bloss nicht!"<br>
property dialogNothingSelectedMessageGerman : "Bitte wähle eine oder mehrere Dateien im Finder aus."<br>
property dialogNothingSelectedButtonGerman : "Okay, mach ich!"<br>
property dialogErrorOccurredMessageGerman : "Ein oder mehr Fehler ist aufgetreten: "<br>
property dialogErrorOccurredButtonGerman : "Och nö!"<br>
<br>
(* UnMain() *)<br>
on run (argv)<br>
(* Init *)<br>
set logMessage to ""<br>
if (my systemLanguage() is "de") then<br>
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01German<br>
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02German<br>
set dialogTooMuchFilesYes to dialogTooMuchFilesYesGerman<br>
set dialogTooMuchFilesNo to dialogTooMuchFilesNoGerman<br>
set dialogNothingSelectedMessage to dialogNothingSelectedMessageGerman<br>
set dialogNothingSelectedButton to dialogNothingSelectedButtonGerman<br>
set dialogErrorOccurredMessage to dialogErrorOccurredMessageGerman<br>
set dialogErrorOccurredButton to dialogErrorOccurredButtonGerman<br>
else<br>
set dialogTooMuchFilesMessage01 to dialogTooMuchFilesMessage01English<br>
set dialogTooMuchFilesMessage02 to dialogTooMuchFilesMessage02English<br>
set dialogTooMuchFilesYes to dialogTooMuchFilesYesEnglish<br>
set dialogTooMuchFilesNo to dialogTooMuchFilesNoEnglish<br>
set dialogNothingSelectedMessage to dialogNothingSelectedMessageEnglish<br>
set dialogNothingSelectedButton to dialogNothingSelectedButtonEnglish<br>
set dialogErrorOccurredMessage to dialogErrorOccurredMessageEnglish<br>
set dialogErrorOccurredButton to dialogErrorOccurredButtonEnglish<br>
end if<br>
<br>
(* Get selected files/folders *)<br>
tell application "Finder"<br>
set selectedItems to selection<br>
(* Check wether something selected *)<br>
if ((count of selectedItems) is greater than 0) then<br>
(* walk through items *)<br>
repeat with oneItem in selectedItems<br>
(* Do dry-run to determine file count *)<br>
set fileCount to 0<br>
tell me to createChecksums(oneItem, true)<br>
log "fileCount: " & fileCount<br>
if (fileCount is greater than 23) then<br>
(* Ask user if he's sure that's what he wants to do *)<br>
display dialog dialogTooMuchFilesMessage01 & fileCount & dialogTooMuchFilesMessage02 buttons {dialogTooMuchFilesYes, dialogTooMuchFilesNo} default button 2<br>
set returnedButton to button returned of result<br>
if (returnedButton is not dialogTooMuchFilesYes) then<br>
tell me to exit repeat #quit<br>
end if<br>
end if<br>
(* Now actually create the checksums *)<br>
set fileCount to 0<br>
tell me to createChecksums(oneItem, false)<br>
end repeat (* loop through sel. files *)<br>
(* If something went wrong -> tell the user *)<br>
if ((count of characters of logMessage) is greater than 0) then<br>
display dialog dialogErrorOccurredMessage & logMessage buttons {dialogErrorOccurredButton} default button 1<br>
end if<br>
else<br>
display dialog dialogNothingSelectedMessage buttons dialogNothingSelectedButton<br>
end if<br>
end tell (* tell finder *)<br>
end run<br>
<br>
(* subroutine for creating md5 checksums *)<br>
on createChecksums(finderItem, dryRun)<br>
try<br>
(* check wether it's a file or a folder, if file create an additional md5 checksum file with similar name *)<br>
tell application "Finder"<br>
set theItemClass to class of finderItem<br>
set theItemName to name of finderItem<br>
set theItemContainer to (container of finderItem) as alias<br>
set itemPath to POSIX path of (finderItem as alias)<br>
set itemContainerPath to POSIX path of theItemContainer<br>
if (theItemClass is folder) then (* not using type because it's localized, class is not *)<br>
(* do this recursive, now with the contents of this folder *)<br>
set aliasList to every item of finderItem (* use of "every file" would result in a list only containing the files *)<br>
if ((count of aliasList) is greater than 0) then<br>
repeat with oneItem in items of aliasList<br>
tell me to createChecksums(oneItem, dryRun)<br>
end repeat<br>
end if<br>
else<br>
(* Don't create checksums of checksums! *)<br>
if (theItemName does not end with ".md5") then<br>
set fileCount to fileCount + 1<br>
(* If dry-running, only increment file counter *)<br>
if (dryRun is not true) then<br>
(* create checksum for file *)<br>
set checksumFileName to theItemName & ".md5"<br>
set cmd to "cd \"" & itemContainerPath & "\" && md5 -q \"" & theItemName & "\" | head -1 > \"" & checksumFileName & "\""<br>
log "Creating md5 checksum with this command: " & cmd<br>
try<br>
tell AppleScript to set cmdRes to do shell script cmd<br>
on error (e)<br>
log "This error occured while creating the checksum file: " & e<br>
end try<br>
log "Creating checksum returned: " & cmdRes<br>
end if (* if dryRun *)<br>
end if<br>
end if (* if file *)<br>
end tell (* tell finder *)<br>
on error (e)<br>
set logMessage to logMessage & "Error: " & e & return<br>
end try<br>
end createChecksums<br>
<br>
on systemLanguage()<br>
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"<br>
<br>
try<br>
tell AppleScript to set languageCode to do shell script cmd<br>
on error (e)<br>
log "WTF? Cannot determine language code."<br>
end try<br>
<br>
if (languageCode is "de") then<br>
log "Deutsch"<br>
else if (languageCode is "en") then<br>
log "English"<br>
else<br>
log "WTF?"<br>
end if<br>
<br>
return languageCode<br>
end systemLanguage<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
(* nothing here *)<br>
----------------------------------------------------------------------
Dumping ./Dial Selected Number.scpt
tell application "System Events" to keystroke "c" using {command down}<br>
delay 0.1<br>
set someword to the clipboard<br>
<br>
tell application "direct" to MakeCall to someword as string<br>
<br>
----------------------------------------------------------------------
Dumping ./Google Images Selected Text.scpt
tell application "System Events" to keystroke "c" using {command down}<br>
delay 0.1<br>
get the clipboard<br>
set someword to the clipboard<br>
<br>
tell application "Safari"<br>
activate<br>
open location "http://google.com/images?q='" & someword & "'"<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./Google Selected Text.scpt
tell application "System Events" to keystroke "c" using {command down}<br>
delay 0.1<br>
set someword to the clipboard<br>
<br>
tell application "Safari"<br>
activate<br>
open location "http://google.com/search?q='" & someword & "'"<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/*****.scpt
tell application "iTunes"<br>
set r to 5<br>
set t to current track<br>
set rating of t to 100 / 5 * r<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/****.scpt
tell application "iTunes"<br>
set r to 4<br>
set t to current track<br>
set rating of t to 100 / 5 * r<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/***.scpt
tell application "iTunes"<br>
set r to 3<br>
set t to current track<br>
set rating of t to 100 / 5 * r<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/**.scpt
tell application "iTunes"<br>
set r to 2<br>
set t to current track<br>
set rating of t to 100 / 5 * r<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/*.scpt
tell application "iTunes"<br>
set r to 1<br>
set t to current track<br>
set rating of t to 100 / 5 * r<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Google Album Artwork Of Current Track.scpt
tell application "iTunes"<br>
# set tName to name of current track<br>
set tArtist to artist of current track<br>
set tAlbum to album of current track<br>
# set queryText to tArtist & " " & tAlbum<br>
set queryText to "\"" & tArtist & "\" \"" & tAlbum & "\""<br>
end tell<br>
<br>
tell application "Safari"<br>
activate<br>
open location "http://google.com/images?q=" & queryText<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Google Lyrics Of Current Track.scpt
tell application "iTunes"<br>
<br>
set tArtist to artist of current track<br>
set tName to name of current track<br>
--set queryText to "lyrics " & tArtist & " " & tName<br>
set queryText to "lyrics \"" & tArtist & "\" \"" & tName & "\""<br>
set queryText to my replace_chars(queryText, "&", "%26") # see http://www.degraeve.com/reference/urlencoding.php<br>
end tell<br>
<br>
tell application "Safari"<br>
activate<br>
open location "http://google.com/search?q=" & queryText<br>
end tell<br>
<br>
# see http://forums.macosxhints.com/archive/index.php/t-26666.html<br>
on replace_chars(this_text, search_string, replacement_string)<br>
set AppleScript's text item delimiters to the search_string<br>
set the item_list to every text item of this_text<br>
set AppleScript's text item delimiters to the replacement_string<br>
set this_text to the item_list as string<br>
set AppleScript's text item delimiters to ""<br>
return this_text<br>
end replace_chars<br>
<br>
----------------------------------------------------------------------
Dumping ./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 *)<br>
tell application "iTunes"<br>
<br>
set l to lyrics of current track<br>
<br>
tell application "TextEdit"<br>
activate<br>
<br>
set newDoc to make new document<br>
set text of newDoc to l<br>
<br>
end tell<br>
<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Paste Current iTunes Track with Album.scpt
tell application "iTunes"<br>
get player state<br>
if player state is not paused and player state is not stopped then<br>
tell current track<br>
set message to artist & " - " & album & " - " & name<br>
end tell<br>
# set artist to  artist of current track<br>
# set album to  album of current track<br>
# set title to name of current track<br>
set the clipboard to message<br>
tell application "System Events" to keystroke "v" using {command down}<br>
end if<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Paste Current iTunes Track.scpt
tell application "iTunes"<br>
get player state<br>
if player state is not paused and player state is not stopped then<br>
tell current track<br>
set message to artist & " - " & name<br>
end tell<br>
set the clipboard to message<br>
tell application "System Events" to keystroke "v" using {command down}<br>
end if<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Show Current Track's Whole Album in Library.scpt
# http://dougscripts.com/itunes/itinfo/info02.php<br>
# http://dougscripts.com/itunes/itinfo/itunes72info.php<br>
tell application "iTunes"<br>
#activate<br>
<br>
display dialog "Not Working yet!"<br>
return<br>
<br>
<br>
<br>
set ct to current track<br>
set tName to name of ct<br>
set tArtist to artist of ct<br>
set tAlbum to album of ct<br>
set queryText to tArtist & " " & tAlbum<br>
#KO set albumTracks to search l for tAlbum only albums<br>
#OK set albumTracks to search playlist "Library" for tAlbum only albums<br>
set albumTracks to (every file track of playlist "Library" whose album contains tAlbum and artist contains tArtist)<br>
log albumTracks<br>
<br>
# Maybe I can select the Library and the tracks with some dirty tricks<br>
tell application "System Events"<br>
tell process "iTunes"<br>
get window 1<br>
#get every item of window 1<br>
#get outlines of window 1<br>
#get buttons of window 1<br>
#get browsers of window 1<br>
#get drawers of window 1<br>
#get lists of window 1<br>
#get text fields of window 1<br>
# Plenty of UI Elements:<br>
get UI elements of window 1<br>
# Splitter Group?<br>
set sg to splitter group of window 1<br>
get UI elements of sg<br>
set u to UI elements of sg<br>
log u # empty<br>
# Grow Area?<br>
set g to grow area 1 of window 1<br>
get UI elements of g<br>
set u to UI elements of g<br>
log u #empty<br>
# scroll area 1 (the yellow thingy)<br>
set s to scroll area 1 of window 1<br>
get UI elements of s<br>
set u to UI elements of s<br>
log u<br>
<br>
end tell<br>
end tell<br>
<br>
<br>
<br>
# Ab hier Bastelbude: #######################<br>
<br>
#set t to first item in albumTracks<br>
#log location of t<br>
#set view of (browser window 1) to parent of t<br>
<br>
(* geht nicht:<br>
reveal file track id 120028 of library playlist id 84927 of source id 48 *)<br>
# set t to first item in albumTracks<br>
# reveal t<br>
<br>
(* geht: <br>
reveal file track id 489116 of user playlist id 488505 of source id 48<br>
<br>
*)<br>
# set t to current track<br>
# reveal t<br>
<br>
<br>
<br>
#KO reveal first item in albumTracks<br>
<br>
#KO reveal playlist "Library"<br>
<br>
#? reveal current track<br>
#KO reveal (first item in albumTracks) of playlist "Library"<br>
<br>
#KO reveal first item in albumTracks<br>
<br>
<br>
(*OK set t to current track<br>
reveal t *)<br>
#OK reveal current track<br>
<br>
# log name of view of (browser window 1)<br>
#log name of view of (front browser window)<br>
<br>
# <br>
#set view of (browser window 1) to library playlist<br>
#set view of (browser window 1) to library playlist 1<br>
<br>
#set view of front browser window to library playlist 1<br>
<br>
<br>
# set l to library playlist<br>
# log l<br>
<br>
<br>
<br>
# log name of l<br>
#log parent of l<br>
# log source of l<br>
<br>
<br>
#log browser window<br>
# set view of front browser window to playlist "Library"<br>
#set view of front browser window to library playlist<br>
<br>
# set view of front browser window to user playlist "Library" of source "Library"<br>
<br>
#set selection to albumTracks<br>
#browser window<br>
end tell<br>
<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Speak Current Track.scpt
tell application "iTunes"<br>
get player state<br>
if player state is not paused and player state is not stopped then<br>
tell current track<br>
set message to "Now playing " & name & " of the album " & album & " from " & artist<br>
end tell<br>
tell AppleScript to say message using "Victoria" (* see http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as304.html *)<br>
end if<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Volume/Decrease (-) Volume.scpt
set whatToDo to "dec" (* can be "inc", "dec", "mute" *)<br>
<br>
<br>
(* 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 *)<br>
set currentVolume to output volume of (get volume settings)<br>
set scaledVolume to round (currentVolume / (100 / 16))<br>
<br>
if (whatToDo contains "mute") then<br>
set volume with output muted<br>
else<br>
if (whatToDo contains "inc") then<br>
(* Use this code to increase the volume by a certain interval *)<br>
set soundInterval to 1<br>
set scaledVolume to scaledVolume + soundInterval<br>
if (scaledVolume > 16) then<br>
set scaledVolume to 16<br>
end if<br>
else if (whatToDo contains "dec") then<br>
(* OR use this code to decrease the output volume by 1 *)<br>
set scaledVolume to scaledVolume - 1<br>
if (scaledVolume < 0) then<br>
set scaledVolume to 0<br>
end if<br>
else<br>
set scaledVolume to scaledVolume<br>
end if<br>
<br>
(* 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) *)<br>
set newVolume to round (scaledVolume / 16 * 100)<br>
set volume output volume newVolume<br>
<br>
end if<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Volume/Increase (+) Volume.scpt
set whatToDo to "inc" (* can be "inc", "dec", "mute" *)<br>
<br>
<br>
(* 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 *)<br>
set currentVolume to output volume of (get volume settings)<br>
set scaledVolume to round (currentVolume / (100 / 16))<br>
<br>
if (whatToDo contains "mute") then<br>
set volume with output muted<br>
else<br>
if (whatToDo contains "inc") then<br>
(* Use this code to increase the volume by a certain interval *)<br>
set soundInterval to 1<br>
set scaledVolume to scaledVolume + soundInterval<br>
if (scaledVolume > 16) then<br>
set scaledVolume to 16<br>
end if<br>
else if (whatToDo contains "dec") then<br>
(* OR use this code to decrease the output volume by 1 *)<br>
set scaledVolume to scaledVolume - 1<br>
if (scaledVolume < 0) then<br>
set scaledVolume to 0<br>
end if<br>
else<br>
set scaledVolume to scaledVolume<br>
end if<br>
<br>
(* 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) *)<br>
set newVolume to round (scaledVolume / 16 * 100)<br>
set volume output volume newVolume<br>
<br>
end if<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Volume/Mute Volume.scpt
set whatToDo to "dec" (* can be "inc", "dec", "mute" *)<br>
<br>
<br>
(* 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 *)<br>
set currentVolume to output volume of (get volume settings)<br>
set scaledVolume to round (currentVolume / (100 / 16))<br>
<br>
if (whatToDo contains "mute") then<br>
set volume with output muted<br>
else<br>
if (whatToDo contains "inc") then<br>
(* Use this code to increase the volume by a certain interval *)<br>
set soundInterval to 1<br>
set scaledVolume to scaledVolume + soundInterval<br>
if (scaledVolume > 16) then<br>
set scaledVolume to 16<br>
end if<br>
else if (whatToDo contains "dec") then<br>
(* OR use this code to decrease the output volume by 1 *)<br>
set scaledVolume to scaledVolume - 1<br>
if (scaledVolume < 0) then<br>
set scaledVolume to 0<br>
end if<br>
else<br>
set scaledVolume to scaledVolume<br>
end if<br>
<br>
(* 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) *)<br>
set newVolume to round (scaledVolume / 16 * 100)<br>
set volume output volume newVolume<br>
<br>
end if<br>
----------------------------------------------------------------------
Dumping ./iTunes Currently Playing Track/Volume/Toggle Mute.scpt
(* Mute/Unute<br>
*)<br>
set _muted to (get (output muted of (get volume settings)))<br>
if _muted is false then<br>
set volume with output muted<br>
else<br>
set volume without output muted<br>
end if<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/*****.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
repeat with aTrack in sel<br>
<br>
set r to 5<br>
set rating of aTrack to 100 / 5 * r<br>
<br>
end repeat<br>
end if<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/****.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
repeat with aTrack in sel<br>
<br>
set r to 4<br>
set rating of aTrack to 100 / 5 * r<br>
<br>
end repeat<br>
end if<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/***.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
repeat with aTrack in sel<br>
<br>
set r to 3<br>
set rating of aTrack to 100 / 5 * r<br>
<br>
end repeat<br>
end if<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/**.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
repeat with aTrack in sel<br>
<br>
set r to 2<br>
set rating of aTrack to 100 / 5 * r<br>
<br>
end repeat<br>
end if<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/*.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to rate " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
repeat with aTrack in sel<br>
<br>
set r to 1<br>
set rating of aTrack to 100 / 5 * r<br>
<br>
end repeat<br>
end if<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Google Album Artwork Of Selected Track.scpt
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
set sel to a reference to selection<br>
if ((count of sel) > 1) then<br>
activate<br>
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!"}<br>
#if <br>
log res<br>
if button returned of res is not "I know what I'm doing" then<br>
return<br>
end if<br>
end if<br>
repeat with aTrack in sel<br>
set tArtist to artist of aTrack<br>
set tAlbum to album of aTrack<br>
set queryText to "\"" & tArtist & "\" \"" & tAlbum & "\""<br>
tell application "Safari"<br>
activate<br>
open location "http://google.com/images?q=" & queryText & ""<br>
end tell<br>
end repeat<br>
end if<br>
end tell<br>
<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Google Lyrics Of Selected Track.scpt
tell application "iTunes"<br>
<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 1 or trackCount is less than 1 then<br>
activate<br>
set msg to "You selected " & trackCount & " tracks. Please select exactly one. Thanks a bunch."<br>
set res to display dialog msg buttons {"Sure!"}<br>
return<br>
end if<br>
<br>
set aTrack to first item in sel<br>
<br>
set tArtist to artist of aTrack<br>
set tName to name of aTrack<br>
set queryText to "lyrics \"" & tArtist & "\" \"" & tName & "\""<br>
set queryText to my replace_chars(queryText, "&", "%26") # see http://www.degraeve.com/reference/urlencoding.php<br>
<br>
tell application "Safari"<br>
activate<br>
# open location "http://google.com/search?q='" & queryText & "'"<br>
open location "http://google.com/search?q=" & queryText & ""<br>
end tell<br>
<br>
end if<br>
<br>
end tell<br>
<br>
<br>
# see http://forums.macosxhints.com/archive/index.php/t-26666.html<br>
on replace_chars(this_text, search_string, replacement_string)<br>
set AppleScript's text item delimiters to the search_string<br>
set the item_list to every text item of this_text<br>
set AppleScript's text item delimiters to the replacement_string<br>
set this_text to the item_list as string<br>
set AppleScript's text item delimiters to ""<br>
return this_text<br>
end replace_chars<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Paste Selected iTunes Tracks with Album.scpt
tell application "iTunes"<br>
<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to do this with the selected " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
set message to ""<br>
repeat with aTrack in sel<br>
<br>
tell aTrack<br>
set message to message & artist & " - " & album & " - " & name & return<br>
end tell<br>
<br>
end repeat<br>
<br>
set the clipboard to message<br>
<br>
tell application "System Events" to keystroke "v" using {command down}<br>
<br>
end if<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Paste Selected iTunes Tracks.scpt
tell application "iTunes"<br>
<br>
if selection is not {} then -- there ARE tracks selected...<br>
<br>
set sel to a reference to selection<br>
set trackCount to count sel<br>
if trackCount is greater than 23 then<br>
set msg to "Are you sure, you want to do this with the selected " & trackCount & " tracks?"<br>
set res to display dialog msg buttons {"Sure!", "Actually, no."}<br>
if button returned of res is not "Sure!" then<br>
return<br>
end if<br>
end if<br>
<br>
set message to ""<br>
repeat with aTrack in sel<br>
<br>
tell aTrack<br>
set message to message & artist & " - " & name & return<br>
end tell<br>
<br>
end repeat<br>
<br>
set the clipboard to message<br>
<br>
tell application "System Events" to keystroke "v" using {command down}<br>
<br>
end if<br>
end tell<br>
<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Play Single Track.scpt
(* <br>
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.<br>
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).<br>
<br>
The bad news: I have no better solution.<br>
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/)<br>
*)<br>
<br>
global tempplaylistname<br>
on run<br>
(* Init *)<br>
<br>
set tempplaylistname to "temp"<br>
<br>
(* Create new playlist, if not existing *)<br>
tell me to set pl to newtempplaylist()<br>
<br>
(* selected track -> pl *)<br>
tell application "iTunes"<br>
<br>
(* remember old playlist *)<br>
set oldpl to view of (browser window 1)<br>
<br>
(* Now the magic... *)<br>
try<br>
get class of selection<br>
# log selection<br>
# if ((count of selection) is greater than 0) then<br>
set t to first item in selection<br>
<br>
(* track into playlist *)<br>
duplicate t to pl<br>
<br>
(* playlist repeat off *)<br>
set song repeat of pl to off<br>
<br>
(* playlist to front *)<br>
try<br>
#set view of front window to playlist pl<br>
#set view of browser window to pl<br>
#set view of (browser window 1) to user playlist pl (*Fuck! (iTunes got an error: A descriptor type mismatch occurred.)*)<br>
set view of (browser window 1) to pl (* Works with iTunes 9 *)<br>
on error (e)<br>
log "Fuck! (" & e & ")"<br>
end try<br>
<br>
(* play track *)<br>
play first item of tracks of pl<br>
<br>
(* Wait until track played or stopped *)<br>
set dur to duration of t<br>
repeat dur times<br>
if player state is not playing then exit repeat<br>
delay 1.0<br>
end repeat<br>
<br>
(* restore old playlist *)<br>
set view of (browser window 1) to oldpl<br>
on error (e)<br>
display dialog "Select something, you weenie!" buttons "Yes, your highness!"<br>
end try<br>
<br>
(* delete temp playlist *)<br>
delete pl<br>
end tell<br>
end run<br>
<br>
(* Create a temp playlist we will delete afterwards *)<br>
on newtempplaylist()<br>
tell application "iTunes"<br>
set pl to make new user playlist with properties {name:tempplaylistname & " as of " & (current date) as string}<br>
end tell<br>
return pl<br>
end newtempplaylist<br>
----------------------------------------------------------------------
Dumping ./iTunes Selected Tracks/Remove Leading  "01" from Title.scpt
tell application "iTunes"<br>
<br>
tell application "iTunes"<br>
if selection is not {} then -- there ARE tracks selected...<br>
set sel to a reference to selection<br>
repeat with aTrack in sel<br>
<br>
set oldName to name of aTrack<br>
log "Processing :" & oldName<br>
<br>
set cmd to "echo \"" & oldName & "\" | sed s/01\\ //\\g"<br>
tell application "Finder"<br>
set newName to do shell script cmd<br>
end tell<br>
log "Setting new name: " & newName<br>
<br>
set name of aTrack to newName<br>
<br>
end repeat<br>
end if<br>
end tell<br>
<br>
end tell<br>
----------------------------------------------------------------------
Dumping ./Leo Selected Text.scpt
(* Copy selected string to clipboard *)<br>
tell application "System Events"<br>
(* Try using Cmd-C *)<br>
set oldClipboard to the clipboard<br>
keystroke "c" using {command down}<br>
set someword to the clipboard<br>
if (oldClipboard is equal to someword) then<br>
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..)"<br>
(* Trying to invoke "Copy" Menu command *)<br>
set appName to name of current application<br>
# my menu_click({appName, my menuEditLocalized(), my menuItemEditCopyLocalized(), ""})<br>
tell application "System Events"<br>
set procs to every process<br>
repeat with p in procs<br>
if frontmost of p is true then<br>
set proc to p<br>
end if<br>
end repeat<br>
#set proc to items of processes whose frontmost is true<br>
#set proc to item 1 of processes<br>
get proc<br>
#click menu item "Copy" of ((proc)'s (menu bar 1)'s (menu bar item "Edit"))<br>
set menuBar to menu bar 1 of proc<br>
set editMenu to menu bar item whose name is (my menuEditLocalized())<br>
return 0<br>
end tell<br>
end if<br>
#delay 0.5<br>
end tell<br>
<br>
<br>
(* Open Browser with query *)<br>
tell application "Safari"<br>
activate<br>
open location "http://dict.leo.org/?search='" & someword & "'"<br>
end tell<br>
<br>
<br>
(* get localized copy menu item name *)<br>
on menuItemEditCopyLocalized()<br>
tell AppleScript<br>
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"<br>
set languageCode to do shell script cmd<br>
if (languageCode is "de") then<br>
return "Kopieren"<br>
else if (languageCode is "en") then<br>
return "Copy"<br>
else<br>
log "WTF?"<br>
return ""<br>
end if<br>
end tell<br>
end menuItemEditCopyLocalized<br>
<br>
<br>
(* get localized copy menu name *)<br>
on menuEditLocalized()<br>
tell AppleScript<br>
set cmd to "defaults read NSGlobalDomain AppleLanguages | grep -v \"^(\" | grep -v \"^)\" | head -1 | cut -d, -f1 | awk '{printf $1}'"<br>
set languageCode to do shell script cmd<br>
if (languageCode is "de") then<br>
return "Bearbeiten"<br>
else if (languageCode is "en") then<br>
return "Edit"<br>
else<br>
log "WTF?"<br>
return ""<br>
end if<br>
end tell<br>
end menuEditLocalized<br>
<br>
<br>
<br>
<br>
(* This came from http://www.macosxhints.com/article.php?story=20060921045743404 *)<br>
on menu_click(mList)<br>
local appName, topMenu, r<br>
<br>
-- Validate our input<br>
if mList's length < 3 then error "Menu list is not long enough"<br>
<br>
-- Set these variables for clarity and brevity later on<br>
set {appName, topMenu} to (items 1 through 2 of mList)<br>
set r to (items 3 through (mList's length) of mList)<br>
<br>
-- This overly-long line calls the menu_recurse function with<br>
-- two arguments: r, and a reference to the top-level menu<br>
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬<br>
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))<br>
end menu_click<br>
<br>
on menu_click_recurse(mList, parentObject)<br>
local f, r<br>
<br>
-- `f` = first item, `r` = rest of items<br>
set f to item 1 of mList<br>
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)<br>
<br>
-- either actually click the menu item, or recurse again<br>
tell application "System Events"<br>
if mList's length is 1 then<br>
click parentObject's menu item f<br>
else<br>
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))<br>
end if<br>
end tell<br>
end menu_click_recurse<br>
----------------------------------------------------------------------
Dumping ./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.<br>
*)<br>
<br>
(* Get selected text *)<br>
tell application "System Events" to keystroke "c" using {command down}<br>
<br>
(* Bring Dictionary to foreground *)<br>
tell application "Dictionary" to activate<br>
<br>
<br>
(* Paste selected text *)<br>
tell application "System Events" to keystroke "v" using {command down}<br>
<br>
<br>
(* Look up *)<br>
# tell application "System Events" to keystroke return<br>
<br>
<br>
<br>
----------------------------------------------------------------------
Dumping ./Paste Log Timestamp.scpt
on run (argv)<br>
# set oldClip to the clipboard<br>
<br>
set the clipboard to my timestamp()<br>
<br>
<br>
tell application "System Events" to keystroke "v" using {command down}<br>
<br>
# set the clipboard to oldClip<br>
end run<br>
<br>
<br>
(* get a time stamp *)<br>
on timestamp()<br>
set dateNow to current date<br>
set dateYear to year of dateNow<br>
set dateMonth to addLeadingZeros(2, (month of dateNow as number))<br>
set dateDay to addLeadingZeros(2, day of dateNow)<br>
set dateHour to addLeadingZeros(2, hours of dateNow)<br>
set dateMinute to addLeadingZeros(2, minutes of dateNow)<br>
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & ", " & dateHour & ":" & dateMinute & ", hk: ") as string<br>
end timestamp<br>
<br>
(* Liefert von einer Zahl n leading zeros zurück *)<br>
on addLeadingZeros(zeroesCount, value)<br>
<br>
(* nimmt die letzten zeroesCount Stellen des Strings *)<br>
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)<br>
log "newNumber: " & newNumber<br>
<br>
return (newNumber)<br>
end addLeadingZeros<br>
<br>
<br>
----------------------------------------------------------------------
Dumping ./Paste Timestamp.scpt
set the clipboard to my timestamp()<br>
<br>
<br>
tell application "System Events" to keystroke "v" using {command down}<br>
<br>
<br>
<br>
(* get a time stamp *)<br>
on timestamp()<br>
set dateNow to current date<br>
set dateYear to year of dateNow<br>
set dateMonth to addLeadingZeros(2, (month of dateNow as number))<br>
set dateDay to addLeadingZeros(2, day of dateNow)<br>
set dateHour to addLeadingZeros(2, hours of dateNow)<br>
set dateMinute to addLeadingZeros(2, minutes of dateNow)<br>
set dateString to (dateYear & "-" & dateMonth & "-" & dateDay & " " & dateHour & ":" & dateMinute) as string<br>
end timestamp<br>
<br>
(* Liefert von einer Zahl n leading zeros zurück *)<br>
on addLeadingZeros(zeroesCount, value)<br>
<br>
(* nimmt die letzten zeroesCount Stellen des Strings *)<br>
set newNumber to (text -zeroesCount thru -1 of ("0000000000000000" & value)) (* Da musch drauf kommen: http://macscripter.net/viewtopic.php?id=24533 *)<br>
log "newNumber: " & newNumber<br>
<br>
return (newNumber)<br>
end addLeadingZeros<br>
<br>
----------------------------------------------------------------------
Dumping ./Reply Mail With Quote.scpt
(* History:<br>
2010-02-21, 16:44, hk: First version.<br>
                                      * If name contains "," reverse order!--DONE<br>
                                      * get original text--DONE<br>
  * check if already quoted, if not-> quote--DONE<br>
  * Leere Zeilen auch quoten--DONE<br>
  * Reply & set new content--DONE<br>
<br>
Bug: Erkennung des schon gequoteten buggt!--?<br>
<br>
ToDo:<br>
<br>
*)<br>
<br>
<br>
tell application "Mail"<br>
# tell message viewer<br>
# get selected messages <br>
# end tell<br>
set selectedMessages to selection<br>
set selectedMessagesCount to (count selectedMessages)<br>
if selectedMessagesCount > 0 then<br>
if selectedMessagesCount > 23 then<br>
set res to display dialog "Are you sure you want to reply on " & selectedMessagesCount & " messages?" buttons {"No", "Maybe", "Yes"}<br>
if button returned of res is not "Yes" then<br>
return<br>
end if<br>
end if<br>
(* Now, do the magic! *)<br>
repeat with selectedMessage in selectedMessages<br>
tell selectedMessage<br>
set smSender to sender<br>
(* cut the email-address *)<br>
tell me to set smSenderName to cutString of smSender by "<"<br>
(* If name contains "," cut the part before the "," and add it at the end (this way "Doe, John" will get "JD" instead of "DJ") *)<br>
if smSenderName contains "," then<br>
log "foo"<br>
tell me to set smSenderNameSurname to cutString of smSenderName by ","<br>
log smSenderNameSurname<br>
tell me to set smSenderNameFirstname to cutStringRemainder of smSenderName by ","<br>
log smSenderNameFirstname<br>
set smSenderName to (smSenderNameFirstname & " " & smSenderNameSurname) as text (* yes, that's ugly *)<br>
log smSenderName<br>
end if<br>
(* get initials of the name *)<br>
tell me to set smInitials to initialsOfName(smSenderName)<br>
(* get text of mail and walk lines... http://www.mactech.com/articles/mactech/Vol.21/21.07/WorkingWithText/index.html *)<br>
set smText to content<br>
set smTextQuoted to ""<br>
#log smText<br>
#set smTextLineCount to count paragraphs of smText<br>
<br>
(* Zeilen (=Paragraphs) abklappern *)<br>
repeat with p in (paragraphs of smText)<br>
<br>
(* Get line length *)<br>
set lineLength to (length of p)<br>
if lineLength > 5 then<br>
set lineLength to 5<br>
end if<br>
<br>
if lineLength > 0 then<br>
set pBegin to characters 1 thru lineLength of p<br>
else<br>
set pBegin to ""<br>
end if<br>
<br>
if pBegin contains ">" then<br>
(* is quoted -> just concatenate strings *)<br>
#log "already quoted: " & pBegin<br>
set smTextQuoted to smTextQuoted & (p as string) & return<br>
else<br>
<br>
#if pBegin does not contain ">" then<br>
(* not quoted yet, quote! *)<br>
set smTextQuoted to smTextQuoted & smInitials & "> " & (p as string) & return<br>
#else<br>
# (* already quoted *)<br>
# set smTextQuoted to smTextQuoted & (p as string) & return<br>
#end if<br>
#else<br>
#set smTextQuoted to smTextQuoted & (p as string) & return<br>
end if<br>
<br>
end repeat (* repeat with paragraphs *)<br>
log "quoted text: " & return & smTextQuoted<br>
end tell # tell selectedMail<br>
<br>
(* Backup quoting behaviour *)<br>
tell application "Mail" to set quotingSetting to quote original message<br>
tell application "Mail" to set quote original message to false<br>
<br>
(* now reply *)<br>
set newMessage to reply selectedMessage with opening window and reply to all<br>
if newMessage is false then<br>
log "Gee, reply failed."<br>
else<br>
tell newMessage<br>
log newMessage<br>
#set content of newMessage to "foo" -- smTextQuoted<br>
# make new content with properties {text:"smTextQuoted"}<br>
log (content)<br>
log (subject)<br>
log (sender)<br>
log (to recipients)<br>
#make new to recipient with properties {address:"MY ADDRESS"}<br>
log (to recipients)<br>
#make new content with t<br>
#log "s: " & (contents as text)<br>
set content to "foo"<br>
set content to smTextQuoted<br>
#make new content with properties {text:"MY text"}<br>
end tell<br>
end if # reply worked<br>
<br>
(* Restore quoting behaviour *)<br>
tell application "Mail" to set quote original message to quotingSetting<br>
<br>
end repeat (* repeat with mails *)<br>
else<br>
log ("You might want to select a message first")<br>
end if<br>
end tell<br>
<br>
(* Now get the first characters of every word (Initials) *)<br>
on initialsOfName(sendername)<br>
set initials to ""<br>
repeat with oneWord in (words of sendername)<br>
set initials to initials & first character of oneWord<br>
end repeat<br>
return initials<br>
end initialsOfName<br>
<br>
(* cuts all the text following the first occurance of the searchstring 'd' *)<br>
to cutString of t by d<br>
set oldd to text item delimiters<br>
set text item delimiters to d<br>
set t to t's text items<br>
set t to first item in t<br>
set text item delimiters to oldd<br>
t<br>
end cutString<br>
<br>
(* returns what cutString has cut off! *)<br>
to cutStringRemainder of t by d<br>
set oldd to text item delimiters<br>
set text item delimiters to d<br>
set t to t's text items<br>
set wordCount to count t<br>
if (wordCount > 1) then<br>
set t to items 2 through wordCount in t<br>
end if<br>
set text item delimiters to oldd<br>
t<br>
end cutStringRemainder<br>
<br>
(* Diese Funktion ersetzt einen String innerhalb eines strings durch einen anderen String. Quelle: http://macscripter.net/viewtopic.php?id=13008 *)<br>
to changeSubString of t from s to r<br>
set d to text item delimiters<br>
set text item delimiters to s<br>
set t to t's text items<br>
set text item delimiters to r<br>
tell t to set t to beginning & ({""} & rest)<br>
set text item delimiters to d<br>
t<br>
end changeSubString<br>
<br>
HeiMac:Little Helpers Scripts heiko$

Revision as of 15:55, 25 September 2010

About

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

What?

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

System Requirements

Download

Media:HeikosLittleHelpers20100823.zip

Setup

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

Usage

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

What it can do for you!

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

(...and much more...)

Sources

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