text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
set theTypes to (item i of theItems)'s |types|() | lns1.scpt |
set strActionType to "ExecuteAppleScript" | lns1.scpt |
set XPathSteps to {¬
"//key['MacroActionType'=text()]", ¬
"/following-sibling::string['" & strActionType & "'=text()]", ¬
"/following-sibling::key['Path'=text()]", ¬
"/following-sibling::string[1]"} | lns1.scpt |
set strXQuery to "for $node in \n" & unlines(XPathSteps) & "\nreturn string($node)" | lns1.scpt |
script showError | lns1.scpt |
display dialog x with title "XQuery applied to plist" | lns1.scpt |
script useResult | lns1.scpt |
concat(concat({¬
either(showError, useResult, ¬
bindLR(readFileLR("~/Desktop/sample.xml"), ¬
valuesFromXQueryLR(strXQuery))), {"\n\nfrom:\n\n"}, {strXQuery}})) | lns1.scpt |
on valuesFromXQueryLR(strXQuery) | lns1.scpt |
on |λ|(strXML) | lns1.scpt |
set eXML to reference | lns1.scpt |
set {docXML, eXML} to (current application's NSXMLDocument's alloc()'s ¬ | lns1.scpt |
initWithXMLString:strXML options:0 |error|:eXML) | lns1.scpt |
if missing value is eXML then | lns1.scpt |
set lrDoc to |Right|(docXML) | lns1.scpt |
set lrDoc to |Left|((localizedDescription of eXML) as string) | lns1.scpt |
script query | lns1.scpt |
on |λ|(docXML) | lns1.scpt |
set eXQ to reference | lns1.scpt |
set {xs, eXQ} to (docXML's objectsForXQuery:strXQuery |error|:eXQ) | lns1.scpt |
if missing value is eXQ then | lns1.scpt |
|Right|(xs as list) | lns1.scpt |
|Left|((localizedDescription of eXQ) as string) | lns1.scpt |
bindLR(lrDoc, query) | lns1.scpt |
end valuesFromXQueryLR | lns1.scpt |
property type : "Either" | lns1.scpt |
property |Left| : x | lns1.scpt |
property |Right| : missing value | lns1.scpt |
property |Left| : missing value | lns1.scpt |
property |Right| : x | lns1.scpt |
on bindLR(m, mf) | lns1.scpt |
if missing value is not |Left| of m then | lns1.scpt |
m | lns1.scpt |
mReturn(mf)'s |λ|(|Right| of m) | lns1.scpt |
end bindLR | lns1.scpt |
on concat(xs) | lns1.scpt |
if 0 < lng and string is class of (item 1 of xs) then | lns1.scpt |
set acc to acc & item i of xs | lns1.scpt |
acc | lns1.scpt |
on either(lf, rf, e) | lns1.scpt |
if missing value is |Left| of e then | lns1.scpt |
tell mReturn(rf) to |λ|(|Right| of e) | lns1.scpt |
tell mReturn(lf) to |λ|(|Left| of e) | lns1.scpt |
end either | lns1.scpt |
if e is missing value then | lns1.scpt |
set str to xs as text | lns1.scpt |
set theText to "Praesent vel sapien lobortis dolor rhoncus congue eget quis ligula. Nulla nunc dolor, malesuada sit amet pharetra sit amet, dapibus eget felis. Mauris eget risus pellentesque, mattis arcu scelerisque, pellentesque metus. Cras maximus convallis tellus. Vivamus mollis nisi quis tincidunt semper. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam sed nisl sapien. Aliquam consectetur tortor nisl, id interdum tortor consequat a." | lns1.scpt |
set theText to current application's NSString's stringWithString:theText | lns1.scpt |
set thePattern to "sapien" | lns1.scpt |
set theArray to (theText's componentsSeparatedByString:thePattern) | lns1.scpt |
set theCount to ((theArray's |count|()) - 1) --> 2 | lns1.scpt |
set testText to theText's mutableCopy() | lns1.scpt |
set theCount to (testText's replaceOccurrencesOfString:thePattern withString:"" options:1024 range:{0, testText's |length|()}) --> 2 | lns1.scpt |
set theScript to ("path:to:script.scpt" as «class furl») | lns1.scpt |
tell application "SatimageOSAX" to set theData to load resource 2000 type "RTF " from theScript as «class utf8» | lns1.scpt |
set theData to (current application's NSString's stringWithString:theData)'s dataUsingEncoding:4 -- NSUTF8StringEncoding | lns1.scpt |
set theRTF to current application's NSAttributedString's alloc()'s initWithRTF:theData documentAttributes:(missing value) | lns1.scpt |
set activeAppID to current application's NSWorkspace's sharedWorkspace()'s frontmostApplication()'s processIdentifier() | lns1.scpt |
(current application's NSRunningApplication's runningApplicationWithProcessIdentifier:activeAppID)'s activateWithOptions:(current application's NSApplicationActivateAllWindows) | lns1.scpt |
set theList to {"One", "Two", "Three", "Four", "Five"} | lns1.scpt |
set theList to current application's NSMutableArray's arrayWithArray:theList | lns1.scpt |
theList's removeObject:"Two" | lns1.scpt |
set URLString to "http://forum.latenightsw.com/t/welcome-to-the-late-night-software-support-forum/8" | lns1.scpt |
set theURL to current application's |NSURL|'s URLWithString:URLString | lns1.scpt |
set theRequest to current application's NSMutableURLRequest's requestWithURL:theURL | lns1.scpt |
theRequest's setValue:"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341" forHTTPHeaderField:"User-Agent" | lns1.scpt |
set {theData, theResponse, theError} to current application's NSURLConnection's sendSynchronousRequest:theRequest returningResponse:(reference) |error|:(reference) | lns1.scpt |
if theData = missing value then error (theError's localizedDescription() as text) | lns1.scpt |
set theCode to theResponse's statusCode() | lns1.scpt |
if theCode is not 200 then error (current application's NSHTTPURLResponse's localizedStringForStatusCode:theCode) as text | lns1.scpt |
set theMimeType to theResponse's MIMEType() | lns1.scpt |
if theMimeType's hasPrefix:"text" then | lns1.scpt |
set theEnc to theResponse's textEncodingName() -- IANA string, so no easy way to convert to usable value | lns1.scpt |
set encodingOptions to current application's NSDictionary's dictionaryWithObject:false forKey:(current application's NSStringEncodingDetectionAllowLossyKey) | lns1.scpt |
set {theEncoding, theString} to current application's NSString's stringEncodingForData:(theData) encodingOptions:encodingOptions convertedString:(reference) usedLossyConversion:(missing value) | lns1.scpt |
if theEncoding = 0 then error "Unknown encoding" | lns1.scpt |
tell application process "Finder" | lns1.scpt |
tell window "Finder" | lns1.scpt |
tell group 7 | lns1.scpt |
tell (first text field whose role description is "search text field") | lns1.scpt |
set its focused to true | lns1.scpt |
set its value to "name:path" | lns1.scpt |
set theData to NSJSONSerialization's dataWithJSONObject:JSON_example2 options:NSJSONWritingPrettyPrinted |error|:(missing value) | lns1.scpt |
set jsonText to (current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)) as text | lns1.scpt |
set theData to mutableDict's objectForKey:"StyledText" | lns1.scpt |
if theData = missing value then -- only plain text | lns1.scpt |
set plainText to mutableDict's objectForKey:"Text" | lns1.scpt |
set plainText to plainText's stringByReplacingOccurrencesOfString:"TEST__" withString:"BLAH__" | lns1.scpt |
set mutableAttString to current application's NSMutableAttributedString's alloc()'s initWithRTFD:theData documentAttributes:(missing value) | lns1.scpt |
set plainString to mutableAttString's |string|() | lns1.scpt |
set theRange to plainString's rangeOfString:"TEST__" | lns1.scpt |
if |length| of theRange = 0 then exit repeat | lns1.scpt |
mutableAttString's replaceCharactersInRange:theRange withString:"BLAH__" | lns1.scpt |
set theData to mutableAttString's RTFDFromRange:{0, mutableAttString's |length|()} documentAttributes:(missing value) | lns1.scpt |
mutableDict's setObject:theData forKey:"StyledText" | lns1.scpt |
mutableDict's setObject:plainString forKey:"Text" | lns1.scpt |
use framework "AppKit" -- needed for initWithHTML: | lns1.scpt |
set theHTML to "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> | lns1.scpt |
<p>Some <b>HTML</b> text</p> | lns1.scpt |
set theHTML to NSString's stringWithString:theHTML | lns1.scpt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.