text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
set nsKey to getItemFromIndexList(nsKeyList, luKeyList, keyName)
|
lns1.scpt
|
set keyDataStr to my getNSKeyValue(itemPath, nsKey)
|
lns1.scpt
|
set itemKeyData to itemKeyData & return & keyName & ":" & tab & keyDataStr
|
lns1.scpt
|
set theClipboard to itemKeyData as text
|
lns1.scpt
|
display dialog itemKeyData with title "ASObjC Key Values for Finder Item"
|
lns1.scpt
|
on getNSKeyValue(pPosixPath, pnsKeyName)
|
lns1.scpt
|
local theURL, theResult, theValue, valueStr
|
lns1.scpt
|
set theURL to current application's class "NSURL"'s fileURLWithPath:pPosixPath
|
lns1.scpt
|
set {theResult, theValue, theError} to theURL's getResourceValue:(reference) forKey:pnsKeyName |error|:(reference)
|
lns1.scpt
|
error (theError's localizedDescription() as text)
|
lns1.scpt
|
set theValue to theValue as list
|
lns1.scpt
|
set valueStr to (item 1 of theValue) as text
|
lns1.scpt
|
if (valueStr = "missing value") or (valueStr = "") then set valueStr to "NOT FOUND"
|
lns1.scpt
|
return valueStr
|
lns1.scpt
|
end getNSKeyValue
|
lns1.scpt
|
on getItemFromIndexList(pMainList, pLookupList, pLookupValue)
|
lns1.scpt
|
local iLU
|
lns1.scpt
|
repeat with iLU from 1 to length of pLookupList
|
lns1.scpt
|
if (item iLU of pLookupList is pLookupValue) then return (item iLU of pMainList)
|
lns1.scpt
|
error "Item NOT Found in List: " & return & "LookupValue: >>>" & pLookupValue & "<<<"
|
lns1.scpt
|
end getItemFromIndexList
|
lns1.scpt
|
use framework "AppKit" -- for NSImage
|
lns1.scpt
|
use framework "Quartz" -- required for PDF stuff
|
lns1.scpt
|
set inFiles to (choose file of type {"public.image", "com.adobe.pdf"} with prompt "Choose your files:" with multiple selections allowed)
|
lns1.scpt
|
set destPosixPath to POSIX path of (choose file name default name "Combined.pdf" with prompt "Save new PDF to:")
|
lns1.scpt
|
its combineFiles:inFiles savingTo:destPosixPath
|
lns1.scpt
|
on combineFiles:inFiles savingTo:destPosixPath
|
lns1.scpt
|
set inNSURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of item 1 of inFiles)
|
lns1.scpt
|
if (inNSURL's pathExtension()'s isEqualToString:"pdf") as boolean then
|
lns1.scpt
|
set theDoc to current application's PDFDocument's alloc()'s initWithURL:inNSURL
|
lns1.scpt
|
set theDoc to my pdfDocFromImageURL:inNSURL
|
lns1.scpt
|
set oldDocCount to theDoc's pageCount()
|
lns1.scpt
|
set inFiles to rest of inFiles
|
lns1.scpt
|
repeat with aFile in inFiles
|
lns1.scpt
|
set inNSURL to (current application's |NSURL|'s fileURLWithPath:(POSIX path of aFile))
|
lns1.scpt
|
set newDoc to (current application's PDFDocument's alloc()'s initWithURL:inNSURL)
|
lns1.scpt
|
set newDoc to (my pdfDocFromImageURL:inNSURL)
|
lns1.scpt
|
set newDocCount to newDoc's pageCount()
|
lns1.scpt
|
repeat with i from 1 to newDocCount
|
lns1.scpt
|
set thePDFPage to (newDoc's pageAtIndex:(i - 1)) -- zero-based indexes
|
lns1.scpt
|
(theDoc's insertPage:thePDFPage atIndex:oldDocCount)
|
lns1.scpt
|
set oldDocCount to oldDocCount + 1
|
lns1.scpt
|
set outNSURL to current application's |NSURL|'s fileURLWithPath:destPosixPath
|
lns1.scpt
|
(theDoc's writeToURL:outNSURL)
|
lns1.scpt
|
end combineFiles:savingTo:
|
lns1.scpt
|
on pdfDocFromImageURL:inNSURL
|
lns1.scpt
|
set theImage to current application's NSImage's alloc()'s initWithContentsOfURL:inNSURL
|
lns1.scpt
|
set theSize to theImage's |size|()
|
lns1.scpt
|
set theRect to {{0, 0}, theSize}
|
lns1.scpt
|
set theImageView to current application's NSImageView's alloc()'s initWithFrame:theRect
|
lns1.scpt
|
theImageView's setImage:theImage
|
lns1.scpt
|
set theData to theImageView's dataWithPDFInsideRect:theRect
|
lns1.scpt
|
return current application's PDFDocument's alloc()'s initWithData:theData
|
lns1.scpt
|
end pdfDocFromImageURL:
|
lns1.scpt
|
tell application id "com.apple.finder" -- Finder.app
|
lns1.scpt
|
set theFiles to selection as alias list
|
lns1.scpt
|
set theURL to (current application's |NSURL|'s fileURLWithPath:(POSIX path of aFile))
|
lns1.scpt
|
set {theResult, theUTI} to (theURL's getResourceValue:(reference) forKey:(current application's NSURLTypeIdentifierKey) |error|:(missing value))
|
lns1.scpt
|
if (theWorkspace's |type|:theUTI conformsToType:"public.image") as boolean then
|
lns1.scpt
|
set end of theList to aFile as item
|
lns1.scpt
|
set thePath to "/Users/shane/Desktop/Example KM Action XML for Variable Prefix.xml" -- change to suit
|
lns1.scpt
|
set newPath to "/Users/shane/Desktop/Example KM Action XML for Variable Prefix modified.xml"
|
lns1.scpt
|
set theData to current application's NSData's dataWithContentsOfFile:thePath
|
lns1.scpt
|
set {theDict, theError} to current application's NSPropertyListSerialization's propertyListWithData:theData options:(current application's NSPropertyListMutableContainersAndLeaves) |format|:(missing value) |error|:(reference)
|
lns1.scpt
|
set theVariables to (theDict's objectForKey:"ElseActions")'s firstObject()'s objectForKey:"Variables"
|
lns1.scpt
|
set thisVariable to theVariables's firstObject()'s objectForKey:"Default"
|
lns1.scpt
|
thisVariable's replaceOccurrencesOfString:"Choice 1" withString:"Choice 3" options:0 range:{0, thisVariable's |length|()}
|
lns1.scpt
|
set {theData, theError} to current application's NSPropertyListSerialization's dataWithPropertyList:theDict |format|:(current application's NSPropertyListBinaryFormat_v1_0) options:0 |error|:(reference)
|
lns1.scpt
|
if theData is missing value then error (theError's localizedDescription() as text)
|
lns1.scpt
|
set theResult to theData's writeToFile:newPath atomically:true
|
lns1.scpt
|
property nsCurApp : a reference to current application
|
lns1.scpt
|
property ptyDebug : false
|
lns1.scpt
|
set xpathStr to "//key[.='Variable']/following-sibling::string[1]"
|
lns1.scpt
|
set xmlPath to "/Users/Shared/Dropbox/SW/DEV/Projects/[KM] Script to Change Variable Names/Example KM Action XML for Variable Prefix.xml"
|
lns1.scpt
|
set nsDataFromXML to nsCurApp's NSData's dataWithContentsOfFile:xmlPath
|
lns1.scpt
|
set {nsXML, theError} to nsCurApp's NSXMLDocument's alloc()'s initWithData:nsDataFromXML options:(nsCurApp's NSXMLDocumentTidyHTML) |error|:(reference)
|
lns1.scpt
|
if nsXML = missing value then error (theError's localizedDescription() as text)
|
lns1.scpt
|
set {nodeArray, theError} to (nsXML's nodesForXPath:xpathStr |error|:(reference)) ##JMTX
|
lns1.scpt
|
if nodeArray = missing value then
|
lns1.scpt
|
return "[ERROR]" & LF & (theError's localizedDescription() as text)
|
lns1.scpt
|
set changedList to {}
|
lns1.scpt
|
repeat with oNode in nodeArray
|
lns1.scpt
|
set nodeString to oNode's stringValue()
|
lns1.scpt
|
set nodeString to (nodeString's stringByReplacingOccurrencesOfString:"ABC(_+)" withString:"Local$1" options:(nsCurApp's NSRegularExpressionSearch) range:{0, nodeString's |length|()})
|
lns1.scpt
|
(oNode's setStringValue:nodeString)
|
lns1.scpt
|
set end of changedList to nodeString as text
|
lns1.scpt
|
set changedXMLStr to (nsXML's XMLStringWithOptions:(nsCurApp's NSXMLNodePrettyPrint)) as text
|
lns1.scpt
|
if ptyDebug then
|
lns1.scpt
|
set oDoc to make new text document with properties {contents:changedXMLStr, source language:"xml"}
|
lns1.scpt
|
return changedList
|
lns1.scpt
|
set theHTML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
lns1.scpt
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
|
lns1.scpt
|
<html xmlns=\"http://www.w3.org/1999/xhtml\">
|
lns1.scpt
|
<head><title></title></head>
|
lns1.scpt
|
<span style=\"color: rgb(51, 51, 51); font-family: 'Open Sans', sans-serif; font-size: 16px; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none;\">
|
lns1.scpt
|
API Documentation Browser
|
lns1.scpt
|
</span>
|
lns1.scpt
|
</body></html>"
|
lns1.scpt
|
set theHTML to current application's NSString's stringWithString:theHTML
|
lns1.scpt
|
set pageHTML to theHTML's dataUsingEncoding:(current application's NSUTF8StringEncoding)
|
lns1.scpt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.