Vorheriges Thema anzeigen :: Nδchstes Thema anzeigen |
Autor |
Nachricht |
ShooTerKo --->


Anmeldedatum: 21.03.2006 Beitrδge: 221 Wohnort: Hamburg
|
Verfasst am: 08.05.2007 - 10:51 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 |
|
Nach oben |
|
 |
iScript ---->


Anmeldedatum: 29.03.2001 Beitrδge: 1116
|
Verfasst am: 15.05.2007 - 07:55 Titel: |
|
|
das ist mir irgendwie 'ne nummer zu hoch. wie wόrde man soetwas denn umsetzen:
replaceOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(unsigned)opts range:(NSRange)searchRange _________________ - anholn deit kriegen - |
|
Nach oben |
|
 |
samowitsch ->

Anmeldedatum: 17.01.2009 Beitrδge: 3
|
Verfasst am: 17.01.2009 - 23:56 Titel: |
|
|
Hallo, bin όber diesen sehr interessanten Thread gestolpert. In einem eigenen Projekt habe ich eine Suchen/Ersetzen Funktion benφtigt und habe mir stringByReplacingOccurrencesOfString:withString: genauer angeschaut. Wollte dieses Snippet diesem Thread zukommen lassen
Zitat: | tell application "Automator"
set resultstring to call method "stringByReplacingOccurrencesOfString:withString:" of sourcestring with parameters {searchstring, replacestring}
end tell |
Sind diese Cocoa Methoden nur όber Automator ansprechbar oder gibt es da noch eine andere Lφsung? Ich finde es lδstig wenn parallel immer Automator aufpoppt.
Beste Grόίe
samowitsch |
|
Nach oben |
|
 |
samowitsch ->

Anmeldedatum: 17.01.2009 Beitrδge: 3
|
Verfasst am: 18.01.2009 - 21:08 Titel: |
|
|
samowitsch hat Folgendes geschrieben: | ..... Sind diese Cocoa Methoden nur όber Automator ansprechbar oder gibt es da noch eine andere Lφsung? Ich finde es lδstig wenn parallel immer Automator ........ |
Jetzt kann ich mir gleich selber Antworten. Innerhalb eines XCode Applescript Studio Projekts kφnnen die Cocoa Klassen direkt und ohne einen "tell app ...." Block angesprochen werden.
Ciao |
|
Nach oben |
|
 |
samowitsch ->

Anmeldedatum: 17.01.2009 Beitrδge: 3
|
Verfasst am: 03.02.2009 - 15:03 Titel: |
|
|
Und hier noch einer:
Code: |
set splitStringList to call method "componentsSeparatedByString:" of sourceString with theDelimiter
|
Eine Cocoa Klasse δhnlich PHP > Explode oder den AppleScript's text item delimiters.
Konnte aber noch nicht vergleichen was schneller ist die Cocoa Klasse oder die AppleScript's text item delimiters |
|
Nach oben |
|
 |
|
|
Du kannst keine Beitrδge in dieses Forum schreiben. Du kannst auf Beitrδge in diesem Forum nicht antworten. Du kannst deine Beitrδge in diesem Forum nicht bearbeiten. Du kannst deine Beitrδge in diesem Forum nicht lφschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
Powered by phpBB © 2001, 2002 phpBB Group Deutsche άbersetzung von phpBB.de
|
|
|