Episoden Benenner – Episode Namer

9/12/2011

Ich bin ja leidenschaftlicher Serien-Gucker, nur das Bennen der aufgezeichneten Sendungen nervt auf Dauer. Deshalb habe ich mir ein kleines Skript gebaut, mit dem sich die Dateien quasi von selber umbenennen.
Das läuft so ab, die Dateien haben meist schon eine teilweise korrekte Namensgebung, z.B. die Laufende Nummer (Folge 23.mp4) oder "S01E03.mp4" oder einfach direkt der Titel "Mr Monk unterwegs als Weihnachtsmann.mp4". Jetzt habe ich mir von meinen Lieblings-Serien Episoden-Listen erstellt in der Form: LaufendeNummer → Season Nummer → EpisodenNummer → Episoden Titel als tab separierte Text-Datei. Diese Benutzt dann das Skript zum erstellen eines Index. Jetzt muss ich nur noch die Datei auf das Skript ziehen, angeben um welche Serie es sich handelt, woran das Skript die jeweilige Episode erkennen kann und wie ich die Episoden benannt haben möchte... zack sind 100 Episoden entsprechend benannt. Zur Sicherheit speichert das Skript aber auch noch den alten Dateinamen im Kommentar der Datei ab.

DOWNLOAD
Episode Benenner v.1.0
95.06 kB (23 hits)
2 Comments

AppleScript Reste-Eintopf II

9/12/2011

Add to Login-Items

--03.09.2008 hubionmac.com

--asks for an app and adds it to login items

addtologin(choose file of type {"APPL"})

on addtologin(thisApp) -- adds an item to login items

set appPath to POSIX path of thisApp

tell application "System Events"

set appName to name of thisApp

set shortName to (characters 1 through ((get offset of ".app" in appName) - 1) of appName) as text

if shortName is not in (name of every login item) then

make login item at end with properties {path:appPath}

end if

end tell

end addtologin

Nach Datei-Endungen sortieren

Das hatte ich mal als Ordner-Aktion für meinen Download-Ordner erdacht... seitdem es Spotlight gibt, hat der Drang Downloads zu sortieren deutlich nachgelassen ;-)

--19.11.2006 hubionmac.com

--Ordneraktion die Dateien an Hand Ihrer Datei-Endung in Unter-Ordner sortiert

on adding folder items to derOrdner after receiving added_items

-- die Liste kann man gut erweitern

set endungmitordner to {".jpg;JPEGS", ".mov;Movies"}

repeat with k in endungmitordner

--damit kann man die Einträge aus der Liste gut in Ihre Bestandteile zerlegen

--Ist auch super um in Strings Teile zu ersetzen =)

set AppleScript's text item delimiters to ";"

set endung to text item 1 of k

set ordnername to text item 2 of k

set AppleScript's text item delimiters to ""

tell application "Finder"

set inhalt to every item of derOrdner

set itemcount to count of every item of inhalt

-- wenn in dem Ordner nix drin ist, soll er auch nix machen... lohnt ja nicht

if itemcount > 1 then

repeat with aitem in inhalt

--Die Anzahl der Buchstabe einer definierten Endung... damit ich am Ende auch weiß ob ich nach

-- .tiff oder .mov suchen muss

set endcount to (-1 * (count of every character of endung))

set itemname to name of aitem

if (characters endcount through -1 of itemname) as text = endung then

--wenn es den ordner schon gibt den fehler ignorieren und weiter im Text

try

make folder at derOrdner with properties {name:ordnername}

end try

--wir basteln uns einen Alias zu einem Verzeichnis

set workingdir to ((derOrdner as string) & ordnername & ":") as alias

--tja und dieser teil bewegt die Datei in den Ordner... und bennent sie um, sofern der

--Name bereits im Zielordner existiert

-- man könnte statt des counters auch die uhrzeit bzw. das datum nehmen...

-- oh ich neheme die Uhrzeit =).

try

move aitem to workingdir as alias

on error

set no_error to false

repeat until no_error = true

set counter to (time of (current date))

try

set name of aitem to (counter & "##" & itemname) as string

move aitem to workingdir as alias

set no_error to true

exit repeat

on error

set no_error to false

end try

end repeat

end try

end if

end repeat

end if

end tell

end repeat

end adding folder items to

Safari Bookmark Saver

Man nehme den Titel und die URL der aktuellen Seite und speichere sie via Skript in einer kleinen HTML-Datei (meta-refresh)... fertig ist das Platform-übergreifende Bookmark-File

--18.01.2005

--Safari Bookmark safer

-- it's not a boookmark but a tiny html file that redirects to the saved URL

set html_text01 to "<html><meta http-equiv=\"refresh\" content=\"0; URL="

set html_text02 to "\"></html>"


tell application "Safari" to set windowcount to count of every window

if windowcount ≥ 1 then

tell application "Safari" to set theurl to URL of document 1

tell application "Safari" to set thename to name of document 1

display dialog "Filename" default answer thename

set thename to text returned of the result

set thetext to html_text01 & theurl & html_text02 as text

do shell script "echo " & quoted form of thetext & "|cat >~/Desktop/" & quoted form of thename & ".html"

end if

Folder-List

Erstelle eine Art Folder-Map... keine Ahnung wofür ich das mal brauchte...

-- 18.3.2007 hubionmac.com.com

-- creates a table of contents (tree structure) of  a folder that was dropped onto the script and saves it into a text file

global theroottxt, thefolder_unix, tabcount

on open thefolder

if (count of thefolder) > 1 then

display dialog "Please put ONE Folder onto the script"

end if

set thefolder to thefolder as alias

set thefolder_unix to POSIX path of thefolder

set theroottxt to thefolder as text

tell application "Finder"

set these_folders to every folder of thefolder

end tell

set tabcount to 0

repeat with this_folder in these_folders

set folderstring to get_folderstring(this_folder)

do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text

do_folder(this_folder)

end repeat

end open




on do_folder(this_folder)

set tabcount to tabcount + 1

tell application "Finder"

set these_folders to every folder of this_folder

end tell

repeat with this_folder in these_folders

set folderstring to get_folderstring(this_folder)

do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text

do_folder(this_folder)

end repeat

set tabcount to tabcount - 1

end do_folder



on get_folderstring(this_folder)

tell application "Finder"

set FolderName to name of this_folder

end tell

repeat with i from 1 to tabcount

set FolderName to tab & FolderName

end repeat

return FolderName as text

end get_folderstring

Rekursions-Beispiel

Würde ich heute ehr mit find -type d lösen, aber geht auch so

--12.10.2005 hubionmac.com

--Beispiel zum Thema Rekursion

global folderkind


set thisfolder to choose folder

display dialog "deepcount=" default answer "0"

set deepcount to text returned of the result as integer

if deepcount = 0 then

process_item(thisfolder)

else

process_folder(thisfolder, deepcount)

end if


on process_folder(this_item, deepcount)

tell application "Finder"

set these_items to every folder of this_item

set deepcount to deepcount - 1

end tell

repeat with this_item in these_items

if deepcount = 0 then

process_item(this_item)

else

process_folder(this_item, deepcount)

end if

end repeat

end process_folder


on process_item(this_item)

tell application "Finder"

set itemname to name of this_item

display dialog itemname

end tell

end process_item

No Comments

AppleScript Reste-Eintopf

4/12/2011

Ich räume gerade meine AppleScript-Verzeichnis auf und dabei sind mir einige Code-Schnipsel untergekommen, die noch nicht hier "archiviert" wurden:

convert aliases into symlinks:

Damit lassen sich wunderbar Aliase in symbolische Links umwandeln. Macht z.B. Sinn, wenn man schnell via Finder Aliase anlegt, die Software, die aber die Dateien braucht nur mit symbolischen Links klar kommt.

set thefolder to choose folder

set thefolderx to POSIX path of (thefolder as alias)

tell application "Finder"

set thealiases to every alias file of thefolder

repeat with thisalias in thealiases

set aliasname to name of thisalias

set theorig to original item of thisalias

set theorigx to POSIX path of (theorig as alias)

do shell script "cd " & quoted form of thefolderx & ";rm " & quoted form of aliasname & ";ln -s " & quoted form of theorigx & " " & quoted form of aliasname

end repeat

end tell

DropTar:

Ich wollte wohl mal via Drag&Drop bzw. eine Finder-Auswahl einfach als .tar.gz packen.... hat sich dank LaunchBar bei mir nun erledigt (da ist so etwas schon eingebaut), der Code landet nun hier

on open these_items

my makeTar(these_items)

end open

on run

tell application "Finder"

set these_items to selection

if these_items = {} then error "Nothing slected"

my makeTar(these_items)

end tell

end run


on makeTar(these_items)

-- READ THE NAME

display dialog "Name of the file:" default answer "" buttons {".TAR", ".TAR.GZ", "cancel"}

copy result as list to dialog01

set tarname to item 1 of dialog01

if tarname = "" then

display dialog "please enter a propper name!" buttons {"cancel"}

else

if (item 2 of dialog01) as text = ".TAR" then

set tarname to (tarname & ".tar") as text

set zz to "-"

else if (item 2 of dialog01) as text = ".TAR.GZ" then

set tarname to (tarname & ".tar.gz") as text

set zz to "-z"

end if

end if

-- READ THE LOCATION WHERE THE FILE SHOULD BE STORED

set save_path to POSIX path of (choose folder with prompt "Where do you wanna save " & tarname & "?")

set thefiles to ""

set first_item to true

repeat with this_item in these_items

tell application "Finder"

-- READ THE FILE's LOCATIONS AND COMPARE THEM

set current_container to container of this_item

if first_item = true then

set item_container to current_container

set first_item to false

end if

-- if the current_containter does not match the general container ERROR!

if item_containercurrent_container then

display dialog "Sorry, this script can only proccess files/folders that at the same location" buttons {"cancel"}

else

-- GET THE ITEMS' NAMES AND LIST THEM

set item_name to name of this_item

set thefiles to thefiles & " \"" & item_name & "\""

end if

end tell

end repeat

-- GET THE POSIX PATH OF THE ITEMS ' CONTAINER

set thefilespath to quoted form of POSIX path of (item_container as alias)

-- MAKE THE COMMAND STRING FOR THE SHELL

set theshellcommand to ("cd " & thefilespath & "; tar " & zz & "cf " & quoted form of ((save_path & tarname) as text) & thefiles) as text

set the clipboard to theshellcommand

-- display dialog theshellcommand

-- DO THE SHELL COMMAND, BECAUSE THIS COULD TAKE SOME TIME... A LONG TIMEOUT SO NO APPLE EVENT TIMEOUT POPS UP =)

with timeout of 3600 seconds

do shell script theshellcommand

end timeout

end makeTar

dmg-maker:

Und hier wollte ich mal per AppleScript ein dmg-Image erstellen...

on open these_

if (count of these_) > 1 then

tell me to quit

end if

tell application "Finder"

set orig_image to quoted form of (POSIX path of item 1 of these_)

set imagename to quoted form of ((name of (item 1 of these_)) as text)

set image_destination to quoted form of POSIX path of (folder of ((item 1 of these_) as alias) as alias)

end tell

set thecommand to ("hdiutil convert " & orig_image & " -format UDZO -imagekey zlinb-level=9 -o " & image_destination & imagename & ".dmg") as text

tell application "Terminal"

run

delay 1

do script with command thecommand

end tell

end open


delete empty folders

Leere Ordner haben mit dem Code fast nichts zu lachen... funktioniert auch nur auf einer Ebene ist also nicht rekursiv geschrieben

on open hubi

tell application "Finder"

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

end open


tell application "Finder"

set hubi to selection

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

delete n chars at beginning/end of filename

tell application "Finder"

set hubi to selection

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

delete .DS_Store

Die Dateien machen oft so gar keinen Sinn und stören mich einfach unter Windows.

set thepath to POSIX path of (choose folder)

set hubi to do shell script "cd " & quoted form of thepath & ";find ./ -name .DS_Store -delete"

display dialog ".DS_Store deleted"

Dateien nach Erstellungsdatum in Ordner sortieren

Ich glaube das war mal ein Versuch meinen Download-Ordner etwas aufgeräumter aussehen zu lassen... alles nur Schein ;-)

--hubionmac.com >~2007 i think

--AppleScript Droplet to sort fieles into folders by creation date

on open these_items

set thelist to {make_dateString(current date, 1)} & {make_dateString(current date, 2)} & {make_dateString(current date, 3)} as list

choose from list thelist with prompt "Choose date format:"

if result as text = item 1 of thelist as text then

set theformat to 1

else if result as text = item 2 of thelist as text then

set theformat to 2

else if result as text = item 3 of thelist as text then

set theformat to 3

end if

repeat with this_item in these_items

tell application "Finder"

-- set thedate to creation date of this_item

set thedate to modification date of this_item

set theLocation to quoted form of POSIX path of ((folder of this_item) as alias)

end tell

set foldername to make_dateString(thedate, theformat)

try

do shell script "cd " & theLocation & ";mkdir " & quoted form of foldername

end try

set the_item to quoted form of POSIX path of this_item

-- 2008-05-26 -n Option add, so files are not overwritten

do shell script "cd " & theLocation & ";mv -n " & the_item & " ./" & quoted form of foldername & "/"

end repeat

end open



on get_month_number(incomingDate)

-- works with systems <OS X 10.4

copy incomingDate to b

set the month of b to January

set month_number to "0" & (1 + (incomingDate - b + 1314864) div 2629728) as text

return (characters -2 through -1 of month_number) as text

end get_month_number


on make_dateString(thedate, theformat)

if theformat = 1 then

set theday to characters -2 through -1 of (("0" & day of thedate) as text) as text

set thestring to (year of thedate) & "-" & get_month_number(thedate) & "-" & theday

else if theformat = 2 then

set thestring to (year of thedate) & "-" & get_month_number(thedate)

else if theformat = 3 then

set thestring to (year of thedate)

end if

return thestring as text

end make_dateString



Rechner ausschalten nach x-Minuten

Das funktioniert, wenn kein Dialog aufgeht... ansonsten müsste man das mit shutdown -now und Admin-Rechten machen...

with timeout of 600000 seconds

display dialog "Shutdown in x Minutes?" default answer 10

set i to (text returned of the result) as integer

delay i * 60

tell application "Finder" to shut down

end timeout

1 Comment

iCal:Arbeitszeiterfassung die 3.

15/09/2011
Sodele ich habe das Skript nun etwas umgeschrieben.
  • das Skript hat nun eine reine Update-Funktion für die Statistik (zur Zeit auf 8 Wochen eingestellt, um bei großen Kalendern die Bearbeitungszeit zur verkürzen)
  • Bei der Statistik werden nun alle nicht-allday-Events berücksichtigt, die eine Dauer größer 1min haben, d.h. Aufgaben werde nun auf die Minute genau erfasst und nicht auf 5min gerundet
  • Die Statstitik wird nun nicht nur für die aktuelle Woche/Monat aktualisiert, sondern für alle Wochen und Monate, die aktuelle Event andauert
  • Das Skript erkennt nun Events an die wie bisher ein Open in der Beschreibung haben, die als Allday-Event angelegt wurden und keine Statistik-Events sind und Events die die gleiche Anfangs- wie Endzeit haben
  • Wählt man ein AllDay-Event zum Abschließen aus, fragt das Skript nach der Anfangs-Uhrzeit des Events.
DOWNLOAD
iCal_Time_Recording_2011_09_15 v.1.3
192.7 kB (110 hits)

@macupdate
@YouTube
2 Comments

Dateiliste in Numbers führen an Hand von Dateinamen

14/09/2011
Ich habe z.B. in Numbers eine Liste mit allen Job-IDs und möchte in einer Spalte daneben alle Dateien aus einem Bestimmten Verzeichnis auflisten, deren Name diese Job-ID beinhaltet... nix leichter als das:

--14.09.2011 hubionmac.com

-- parts of numbers selection code by http://hints.macworld.com/article.php?story=20090109055630154

-- requested @https://discussions.apple.com/thread/3325583?tstart=0

-- this script takes the value of a selection in numbers first and a asks for a folder

-- then the values of the first column of the selection are taken and all filenames of start start with that folder and are found in the defined folder will be

-- writen to the last column of the selection ----> you will have to select at least 2 columns


set thefolder to quoted form of POSIX path of ((choose folder) as alias)


tell application "Numbers"

activate

tell document 1

-- DETERMINE THE CURRENT SHEET

set current_sheet_index to 0

repeat with i from 1 to the count of sheets

tell sheet i

set x to the count of (tables whose selection range is not missing value)

end tell

if x is not 0 then

set the current_sheet_index to i

exit repeat

end if

end repeat

if the current_sheet_index is 0 then error "No sheet has a selected table."

-- GET THE VALUES OF THE SELECTED CELLS

tell sheet current_sheet_index

set the current_table to the first table whose selection range is not missing value

tell the current_table

set range_column_count to count of every column of selection range

set this_rows_first_cell_index to 1

set this_rows_last_cell_index to range_column_count

-- THIS CHANGES THE VALUE OF 

repeat with i from 2 to count of every cell of selection range

set thename to value of cell this_rows_first_cell_index of selection range

set foundfilenames to my find_filenames(thefolder, thename)

set value of cell this_rows_last_cell_index of selection range to foundfilenames

set this_rows_first_cell_index to this_rows_first_cell_index + range_column_count

set this_rows_last_cell_index to this_rows_last_cell_index + range_column_count

if this_rows_last_cell_index > (count of every cell of selection range) then exit repeat

end repeat

end tell

end tell

end tell

end tell



on find_filenames(thefolder, filename_start)

-- THIS SEARCHES FILES STARTING WITH A SPECIFIC STRING IN THEIR NAMES AND OUTPUTS JUST THEIR FILENAMES

-- IS SEARCHES IN THEFOLDER AND ALL SUB-DIRECTORIES

set theoutput to do shell script "cd " & thefolder & ";find " & "." & " -iname \"" & filename_start & "*\""

if theoutput ≠ "" then

set theoutput to every paragraph of theoutput

--OPTIONAL REMOVE THE FIRST CHARACTER OF EACH PATH

set tmp to {}

repeat with t in theoutput

set tmp to tmp & {(characters 2 through -1 of t) as text}

end repeat

set theoutput to tmp

set AppleScript's text item delimiters to "; "

set theoutput to theoutput as text

set AppleScript's text item delimiters to ""

end if

return theoutput

end find_filenames

No Comments

RGB Farbcode zu HTML und umgekehrt

16/03/2011

Wenn man in AppleScript eine Farbe angibt (z.B. für einen Text) so geschieht das über eine RGB-Farbwert-Angabe wie {255,5645,4565}. Das Besonder daran, es können eben 16,7 Millionen Farbwerte sein (256*256*256) + jeweils 256 mögliche Werte für den Grad der Transparenz (so glaube ich). Ich fand auch schnell eine Routine zum umwandeln solcher RGB-Werte in HTML-Werte, doch für die andere Richtung schien es nichts zu geben... hier also die Orig-Routine von macosxautomation und meine Routine, die das exakte Gegenteil bewirkt.

set html to RBG_to_HTML({0, 22359, 30583})

return HTML_to_RGB(characters 2 through -1 of html as text)


on RBG_to_HTML(RGB_values)

-- NOTE: this sub-routine expects the RBG values to be from 0 to 65535

set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}

set the the hex_value to ""

repeat with i from 1 to the count of the RGB_values

set this_value to (item i of the RGB_values) div 256

if this_value is 256 then set this_value to 255

set x to item ((this_value div 16) + 1) of the hex_list

set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list

set the hex_value to (the hex_value & x & y) as string

end repeat

return ("#" & the hex_value) as string

end RBG_to_HTML


on HTML_to_RGB(HTML_value)

-- NOTE: this sub-routine expects the HTML values to have 6 characters

set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}

set the the RGB_value to {}

set HTML_values to {characters 1 through 2 of HTML_value as text, characters 3 through 4 of HTML_value as text, characters 5 through 6 of HTML_value as text}

repeat with HTML_value in HTML_values

repeat with i from 1 to count of hex_list

if character 1 of HTML_value = item i of hex_list then

set firstvalue to (i - 1) * 16

end if

end repeat

repeat with i from 1 to count of hex_list

if character 2 of HTML_value = item i of hex_list then

set secondvalue to (i - 1) * 1

end if

end repeat

set RGB_value to RGB_value & (firstvalue + secondvalue) * 257

end repeat

return RGB_value

end HTML_to_RGB

No Comments

iCal: Liste der heutigen Events

11/03/2011
Gibt eine Liste der Events aus, die am heutigen Tag beginnen und auch enden...

getThisDaysEvents_List("Hubi")


on getThisDaysEvents_List(calendarname)

tell application "iCal"

set startdate to (current date) - ((minutes of (current date)) * 60) - ((hours of (current date)) * 60 * 60) - (seconds of (current date))

set enddate to startdate + (3600 * 24)

tell calendar calendarname

set eventnames to summary of every event whose start date > startdate and end date < enddate

set event_starts to start date of every event whose start date > startdate and end date < enddate

end tell

set myoutput to ""

repeat with i from 1 to count of eventnames

set myoutput to myoutput & "" & (characters 1 through -4 of (time string of item i of event_starts)) & "  " & item i of eventnames & return

end repeat

set myoutput to my BubbleSort(every paragraph of myoutput)

set AppleScript's text item delimiters to return

set myoutput to myoutput as text

set AppleScript's text item delimiters to ""

return "Events @ " & date string of (current date) & ":" & return & myoutput

end tell

end getThisDaysEvents_List

on BubbleSort(theList)

if class of theList is list then

set theSize to length of theList

repeat with i from 1 to theSize

repeat with j from 2 to (theSize - i + 1)

if ((item (j - 1) of theList) > (item j of theList)) then

set temp to (item (j - 1) of theList)

set (item (j - 1) of theList) to (item j of theList)

set (item j of theList) to temp

end if

end repeat

end repeat

return theList

else

return false

end if

end BubbleSort

No Comments

Das soll mal AppleScript ganz egal sein…

11/03/2011
Mir ist zwar eine Sinnvolle Anwendung dafür noch nicht untergekommen, aber es funktioniert... damit ist AppleScript alles schei** egal.

tell application "TextEdit"

activate

set a to make new document

set text of a to "blafasel"

beep

ignoring application responses

quit

end ignoring

end tell

No Comments

AppleScript per Weblink starten….

25/02/2011

Ich dachte eigentlich, dass so etwas nicht möglich ist, dabei mache ich bei meinen Quellcode-Containern auf dieser Seite nix anderes. Ludwig_M hat mir aber die Augen geöffnet und mir eine Idee für ein schönes Beispiel-Skript geliefert =)
Anbei eine Bespiel-Seite mit entsprechenden Links und ein dazu passendes AppleScript. Ein entsprechendes Video ist auch dabei...

DOWNLOAD
SayThis Weblink (sample) v.
28.42 kB (107 hits)
1 Comment

Mail Applescript Bug

16/02/2011
Ist schon komisch in Apple Mail macht es teilweise einen gewaltigen Unterschied ob ein Skript so läuft oder in Folge eine Regel ausgeführt wird. Dabei scheint es hier aber ehr ein Fehler in der Implementierung zu sein... lasse ich dieses Skript von einer Regel ausführen:

on perform_mail_action(info)

tell application "Mail" to display dialog (count (every message of mailbox "INBOX" of account "1")) as text

end perform_mail_action

bekomme ich im Dialog stehst eine 1 ausgegeben und in der Konsole läuft folgender Fehler auf. 16.02.11 01:36:24 Mail[189] A key or value could not be handled while converting an Apple event record to an NSDictionary. Klicke ich direkt auf eine Email und wähle im Kontext-Menü "Regel Anwenden" aus, erscheint die korrekte Anzahl...
No Comments