| ShooTerKo --->
 
  
  
 Anmeldedatum: 21.03.2006
 Beitrδge: 221
 Wohnort: Hamburg
 
 | 
			
				|  Verfasst am: 07.05.2007 - 12:29    Titel: Objective-C Calls in Applescript |   |  
				| 
 |  
				| So, ich habe mich mal etwas schlau gemacht und ein bisschen mit Objective-C bzw. Cocoa-Strings herumgespielt: VIEL SPASS!
 
 (*
 
 Ein paar Beispiele von String-Handlern in Applescript
 
 Der tell application "Automator"-Block ist nur notwendig fόr das Scripten
 im ScriptEditor und entfδllt beim Scripten in Applescript Studio (Xcode)
 
 
 Weitere Informationen zum call method() Handler
 http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/chapter04/chapter_4_section_2.html#//apple_ref/doc/uid/20001251-TPXREF175
 
 Weitere Mφglichkeiten zur NSString-Klasse unter
 http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
 
 Klassenmethoden (zu erkennen am + vor der Signatur) werden mit
 of class "NSString"
 aufgerufen und geben einen neu erzeugten String
 
 Bei Aufruf von Funktionen mit Parametern muί der Doppelpunkt mitgeschrieben werden, und die Parameter als Liste mit όbergeben werden z.B.
 call method "stringByAppendingPathComponent:" of "~/Library/" with parameters {"Application Support"}
 
 
 *)
 
 --
 -- Verδndern der Groί- und Kleinschreibung
 --
 -- Alles Groίbuchstaben (uppercase)
 set foo to "The quick brown fox jumps over the lazy dog."
 tell application "Automator"
 set uppercasedString to call method "uppercaseString" of foo
 end tell
 
 -- Alles Kleinbuchstaben (lowercase)
 set foo to "The quick brown fox jumps over the lazy dog."
 tell application "Automator"
 set lowercasedString to call method "lowercaseString" of foo
 end tell
 
 -- Kapitalisieren (capitalize)
 set foo to "The quick brown fox jumps over the lazy dog."
 tell application "Automator"
 set capitalizedString to call method "capitalizedString" of foo
 end tell
 
 --
 -- Arbeiten mit Pfaden
 --
 
 -- Tilde (~) auflφsen
 set foo to "~/Library/Application Support"
 tell application "Automator"
 set fullPathString to call method "stringByExpandingTildeInPath" of foo
 end tell
 
 -- Tilde (~) wieder hineinrechnen
 set foo to POSIX path of (path to desktop folder)
 tell application "Automator"
 set pathStringWithTilde to call method "stringByAbbreviatingWithTildeInPath" of foo
 end tell
 
 -- Parent-Folder holen
 set foo to "~/Library/Application Support"
 tell application "Automator"
 set parentPath to call method "stringByDeletingLastPathComponent" of foo
 end tell
 
 -- Pfad um Komponente erweitern
 set foo to "~/Library/"
 tell application "Automator"
 set deeperPath to call method "stringByAppendingPathComponent:" of foo with parameters {"Application Support"}
 end tell
 
 -- Pfadkomonenten als Liste holen
 set foo to "~/Library/Application Support"
 tell application "Automator"
 set foo to call method "stringByExpandingTildeInPath" of foo
 set pathComponentsList to call method "pathComponents" of foo
 end tell
 
 -- Mehrere Pfade gleichzeitig bauen
 set foo to "/Applications"
 set fooList to {"Utilities/Terminal.app", "iTunes.app", "Dictionary.app"}
 tell application "Automator"
 set pathList to call method "stringsByAppendingPaths:" of foo with parameters {fooList}
 end tell
 
 -- einen kompletten Pfad bauen
 set fooList to {"Applications", "Utilities", "Terminal.app"}
 tell application "Automator"
 set theNewPath to call method "pathWithComponents:" of class "NSString" with parameters {fooList}
 end tell
 
 --
 -- Arbeiten mit URLs
 --
 
 -- eine URL encoden
 set foo to "http://www.spiegel.de/δφό"
 tell application "Automator"
 set theNewPath to call method "stringByAddingPercentEscapesUsingEncoding:" of foo with parameter 5
 --> ergibt "http://www.spiegel.de/%E4%F6%FC"
 end tell
 
 -- eine URL decoden
 tell application "Automator"
 set theNewestPath to call method "stringByReplacingPercentEscapesUsingEncoding:" of "http://www.spiegel.de/%E4%F6%FC" with parameter 5
 --> ergibt "http://www.spiegel.de/δφό"
 end tell
 
 (*
 NSASCIIStringEncoding = 1,
 NSNEXTSTEPStringEncoding = 2,
 NSJapaneseEUCStringEncoding = 3,
 NSUTF8StringEncoding = 4,
 NSISOLatin1StringEncoding = 5,
 NSSymbolStringEncoding = 6,
 NSNonLossyASCIIStringEncoding = 7,
 NSShiftJISStringEncoding = 8,
 NSISOLatin2StringEncoding = 9,
 NSUnicodeStringEncoding = 10,
 NSWindowsCP1251StringEncoding = 11,
 NSWindowsCP1252StringEncoding = 12,
 NSWindowsCP1253StringEncoding = 13,
 NSWindowsCP1254StringEncoding = 14,
 NSWindowsCP1250StringEncoding = 15,
 NSISO2022JPStringEncoding = 21,
 NSMacOSRomanStringEncoding = 30,
 NSProprietaryStringEncoding = 65536
 *)
 
 
 Vielleicht kφnnen wir ja so nach und nach tolle Funktionalitδten von call method hier hineinstellen, ich denke, dass es da noch seeeehr viel zu entdecken gibt!
     
 Viele Grόίe,
 ShooTerKo
 _________________
 "It is a mistake to think you can solve any major problems just with potatoes." - Douglas Adams
 |  | 
	
		| iScript ---->
 
  
  
 Anmeldedatum: 29.03.2001
 Beitrδge: 1116
 
 
 | 
			
				|  Verfasst am: 08.05.2007 - 10:45    Titel: |   |  
				| 
 |  
				| Du bist sooo cool, mann  ! Ich werd' mir das mit Sicherheit, sofern mehr Zeit vorhanden, mal genauer anschauen. Wόrd's im Snippet-Forum aber besser aufgehoben finden!
 Vielen Dank schon mal fόr die Tipps, die Mόhe, und daί du uns teilhaben lδίt! Da ist ja jetzt schon einiges dabei, daί man gut brauchen kann! SupiSache!
 _________________
 - anholn deit kriegen -
 |  |