text
stringlengths
0
15.7k
source
stringlengths
6
112
set theData to theHTML's dataUsingEncoding:NSUTF8StringEncoding
lns1.scpt
set theATS to NSAttributedString's alloc()'s initWithHTML:theData documentAttributes:(missing value)
lns1.scpt
set theText to theATS's |string|() as text
lns1.scpt
set pageURL to current application's |NSURL|'s URLWithString:"https://latenightsw.com/sd7/edit/"
lns1.scpt
set {theData, theError} to current application's NSData's dataWithContentsOfURL:pageURL options:0 |error|:(reference)
lns1.scpt
if theATS is missing value then error "Could not read HTML file"
lns1.scpt
if theATS is missing value then error "Could not interpret HTML"
lns1.scpt
use framework "AppKit" -- needed for used rtf methods
lns1.scpt
property NSRTFTextDocumentType : a reference to current application's NSRTFTextDocumentType
lns1.scpt
set posixPath to POSIX path of (choose file with prompt "Choose an RTF file" of type {"rtf"})
lns1.scpt
set theData to NSData's dataWithContentsOfFile:posixPath
lns1.scpt
set {theStyledString, docAttributes} to NSAttributedString's alloc()'s initWithRTF:theData documentAttributes:(reference)
lns1.scpt
if theStyledString is missing value then error "Could not read RTF file"
lns1.scpt
set theStyledString to theStyledString's mutableCopy()
lns1.scpt
theStyledString's replaceCharactersInRange:{0, 0} withString:("Extra text" & linefeed)
lns1.scpt
set theData to theStyledString's RTFFromRange:{0, theStyledString's |length|()} documentAttributes:docAttributes
lns1.scpt
set posixPath to NSString's stringWithString:posixPath
lns1.scpt
set newPath to (posixPath's stringByDeletingPathExtension()'s stringByAppendingString:"-copy")'s stringByAppendingPathExtension:(posixPath's pathExtension())
lns1.scpt
theData's writeToFile:newPath atomically:true
lns1.scpt
set docAttributes to {DocumentType:NSRTFTextDocumentType}
lns1.scpt
set nsPlainText to theAttString's |string|()
lns1.scpt
set theRange to (nsPlainText's rangeOfString:reFind options:NSRegularExpressionSearch)
lns1.scpt
theAttString's replaceCharactersInRange:theRange withString:reReplace
lns1.scpt
set {theRegex, theError} to current application's NSRegularExpression's regularExpressionWithPattern:reFind options:0 |error|:(reference)
lns1.scpt
set theMatches to (theRegex's matchesInString:nsPlainText options:0 range:{0, nsPlainText's |length|()}) as list
lns1.scpt
set theMatches to reverse of theMatches -- so you work from back to front to keep ranges accurate
lns1.scpt
(theAttString's replaceCharactersInRange:(aMatch's range()) withString:reReplace)
lns1.scpt
set newString to (theRegex's replacementStringForResult:aMatch inString:nsPlainText |offset|:0 template:reReplace)
lns1.scpt
(theAttString's replaceCharactersInRange:(aMatch's range()) withString:newString)
lns1.scpt
set theArray to thePasteboard's readObjectsForClasses:{current application's class "NSString"} options:(missing value)
lns1.scpt
set theString to (theArray's componentsJoinedByString:return) as text
lns1.scpt
property NSFileManager : class "NSFileManager"
lns1.scpt
property NSString : reference to current application's NSString
lns1.scpt
property NSFileManager : reference to current application's NSFileManager
lns1.scpt
set theFile to current application's NSURL's fileURLWithPath:"/Users/zerafio/Desktop/test1.pdf"
lns1.scpt
set theDest to current application's NSURL's fileURLWithPath:"/Users/zerafio/Desktop/test2.pdf"
lns1.scpt
set theDoc to current application's PDFDocument's alloc()'s initWithURL:theFile
lns1.scpt
set thePage to (theDoc's pageAtIndex:0)
lns1.scpt
set {{pL, pB}, {pW, pH}} to (thePage's boundsForBox:(current application's kPDFDisplayBoxMediaBox))
lns1.scpt
set theAnnot to current application's PDFAnnotation's alloc's initWithBounds:{{pL + 20, pH - 40}, {pW - 40, 20}} forType:(current application's PDFAnnotationSubtypeWidget) withProperties:(missing value)
lns1.scpt
theAnnot's setWidgetFieldType:(current application's PDFAnnotationWidgetSubtypeText)
lns1.scpt
theAnnot's setFieldName:"textField"
lns1.scpt
theAnnot's setWidgetStringValue:"Mon paletot aussi devenait idéal"
lns1.scpt
theAnnot's setAlignment:0
lns1.scpt
theAnnot's setFont:(current application's NSFont's fontWithName:"Helvetica" |size|:12)
lns1.scpt
theAnnot's setBackgroundColor:(current application's NSColor's clearColor())
lns1.scpt
thePage's addAnnotation:theAnnot
lns1.scpt
theDoc's writeToURL:theDest
lns1.scpt
set theConfig to current application's NSWorkspaceOpenConfiguration's new()
lns1.scpt
theConfig's setActivates:true
lns1.scpt
set appURL to (theWorkspace's URLForApplicationWithBundleIdentifier:"com.apple.Preview")
lns1.scpt
(theWorkspace's openURLs:{theDest} withApplicationAtURL:appURL configuration:theConfig completionHandler:(missing value))
lns1.scpt
set theNumber to 64
lns1.scpt
log "sqrt: " & (do shell script "/usr/bin/python3 <<EOF
lns1.scpt
import math
lns1.scpt
print(math.sqrt(" & theNumber & "))
lns1.scpt
set theNumber to 5
lns1.scpt
log "log10: " & (do shell script "/usr/bin/python3 <<EOF
lns1.scpt
print(math.log10(" & theNumber & "))
lns1.scpt
on log10 (TheNumber)
lns1.scpt
set natural_log to (do shell script ("echo 'l(" & (TheNumber as string) & ")' | bc -l")) as real
lns1.scpt
set natural_log_of_10 to (do shell script ("echo 'l(10)' | bc -l")) as real
lns1.scpt
set common_log to natural_log / natural_log_of_10
lns1.scpt
return common_log
lns1.scpt
on sqrtf(base)
lns1.scpt
return base ^ 0.5
lns1.scpt
end sqrtf
lns1.scpt
on min(num1, num2)
lns1.scpt
if num1 < num2 then
lns1.scpt
return num1
lns1.scpt
return num2
lns1.scpt
set displayID to current application's CGMainDisplayID()
lns1.scpt
set cursorPoint to current application's NSMakePoint(10, 10)
lns1.scpt
set hadError to current application's CGDisplayMoveCursorToPoint(displayID, cursorPoint)
lns1.scpt
if hadError as boolean then error "Set mouse position failed."
lns1.scpt
set cursorPoint to current application's NSMakePoint(500, 500)
lns1.scpt
current application's CGWarpMouseCursorPosition(cursorPoint)
lns1.scpt
set theXMLString to _XmlDoc's XMLStringWithOptions:(current application's NSXMLNodePrettyPrint)
lns1.scpt
set pdfFile to POSIX path of (choose file of type {"com.adobe.pdf"})
lns1.scpt
set pageNumber to 0 -- set to 0 for all pages
lns1.scpt
set pdfText to getText(pdfFile, pageNumber)
lns1.scpt
on getText(theFile, pageNumber) -- theFile is POSIX path
lns1.scpt
set theDocument to current application's PDFDocument's alloc()'s initWithURL:theFile
lns1.scpt
if pageNumber = 0 then
lns1.scpt
set theText to theDocument's |string|()
lns1.scpt
set theText to (theDocument's pageAtIndex:(pageNumber - 1))'s |string|()
lns1.scpt
set theWhitespace to "(?m)^\\h+|\\h+$"
lns1.scpt
return (theText's stringByReplacingOccurrencesOfString:theWhitespace withString:"" options:(current application's NSRegularExpressionSearch) range:{0, theText's |length|()}) as text
lns1.scpt
end getText
lns1.scpt
use AppleScript version "2.5" -- macOS 10.11 or later
lns1.scpt
property theResult : missing value
lns1.scpt
property theError : missing value
lns1.scpt
on runWorkflow:theObject
lns1.scpt
set {theURL, theInput} to theObject as list
lns1.scpt
set {my theResult, my theError} to current application's AMWorkflow's runWorkflowAtURL:(theURL) withInput:theInput |error|:(reference)
lns1.scpt
end runWorkflow:
lns1.scpt
set theInput to "use framework \"Foundation\"
lns1.scpt
use theLib : script \"BridgePlus\"
lns1.scpt
set theString to theLib's sortListOfNumbers:{9, 2, 7, 3, 6, 4}
lns1.scpt
set thePath to "/Users/f.gustafsson.user/Desktop/runAS.workflow"
lns1.scpt