Originally, AppleScript invoked an application's internal functionality through an AppleScript dictionary of terms.
Operations such as clicking buttons and operating menus depend on the state of the application being operated, so various know-how is required.
It's normal to write out system information as CSV data.
All the know-how about GUI Scripting is summarized in an e-book, so it may be helpful.
https://piyomarusoft.booth.pm/items/4230018
Post
Replies
Boosts
Views
Activity
If you're talking about "private browsing mode" as "incognito mode", it's easy.
You can control FireFox by using GUI Scripting (via System Events).
"keystroke" command can make key press event. "click" command can make menu click event.
Whole GUI Scripting how-to is in my ebook.
https://piyomarusoft.booth.pm/items/4230018
"repeat with x in xList..." returns a reference of array.
So, some command accept a reference and other command does not accept it.
We have to change the reference into real data.
"as string" would be a good way of writing to abbreviate the explanation. However, it may be a way of writing that gives a sense of incongruity to those who emphasize principles.
We have to convert or access reference by using "contents of".
set aList to {"1", "2", "3", "4", "5"}
repeat with i in aList
set j to contents of i
say j
end repeat
You can find such a description in AppleScript example blogs...
http://piyocast.com/as/search_gcse?q=contents%20of
You can execute JavaScript in AppleScript by using WebKit or JavaScriptCore.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "JavaScriptCore"
use framework "WebKit"
--JavaScript Text
set jsText to "let bar = 2;
bar += 2;
"
--Execute JavaScript in WebKit
set theWebView to current application's WebView's alloc()'s init()
set x to (theWebView's stringByEvaluatingJavaScriptFromString:jsText) as text
log {x, "2"}
--Execute JavaScript in JavaScript Core
set theContext to current application's JSContext's alloc()'s init()
set theJSValue to theContext's evaluateScript:jsText
log {theJSValue, "3"}
You have to execute this AppleScript on Script Editor by Control-Command-R(Run in Main thread).
I wrote an ebook about remote drive mount AppleScript.
https://piyomarusoft.booth.pm/items/3909458
Contents:
--How to check the location of each drive
--Check file server existence by Randezvous
--How to write "mount drive" command.
NSAttributedString can handle RTF or RTFD. I don't think it can handle Word documents (.docx). Check it at first.
And...You can not debug it with Terminal.app (osascript).
You have to use LateNight Software's Script Debugger.
https://latenightsw.com/
Smarter restart AppleScript is here.
tell application "loginwindow" to «event aevtrrst»
My blog "AppleScript Hole" hosts thousands of AppleScript examples. Each "★Click Here to Open This Script" link in each AppleScript program list will transfer script source.
http://piyocast.com/as/
I checked .heic images on my Mac mini M1 (macOS 13.3beta) by using your script.
One heic images returns
{"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "space", "bitsPerSample", "formatOptions", "pixelHeight", "profile", "path", "pixelWidth", "format", "typeIdentifier"}
But most of images returns
{"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "bitsPerSample", "profile", "formatOptions", "ExifColorSpace", "pixelHeight", "path", "creation", "software", "space", "pixelWidth", "format", "make", "model", "typeIdentifier"}
So, I don't think Image Events can not read "creation" Exif value. Today macOS has various bugs everywhere. Importer program is doubtful.
The heic image which returns {"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "space", "bitsPerSample", "formatOptions", "pixelHeight", "profile", "path", "pixelWidth", "format", "typeIdentifier"} did not return creation date by another AppleScript execution.
-- Created 2014-12-14 by Takaaki Naganoya
-- 2014 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BPlus : script "BridgePlus" --https://www.macosxautomation.com/applescript/apps/BridgePlus.html
property NSString : a reference to current application's NSString
property NSLocale : a reference to current application's NSLocale
property SMSForder : a reference to current application's SMSForder
property NSDateFormatter : a reference to current application's NSDateFormatter
set aTargFile to choose file of type {"public.image"}
set exifRes to readExifDateTimeOriginal(aTargFile) of me
--指定ファイルからのExifデータを取得し撮影日付を取得する
on readExifDateTimeOriginal(aTargFileAlias)
set theMetadata to readMetadataFrom(aTargFileAlias) of me
set keysList to theMetadata's allKeys()
if "{Exif}" is not in (keysList as list) then return false
set exifDate to theMetadata's valueForKeyPath:"{Exif}.DateTimeOriginal"
if exifDate = missing value then return false
set fullDate to dateFromStringWithDateFormat(exifDate, "yyyy:MM:dd HH:mm:ss") of me
return fullDate
end readExifDateTimeOriginal
--指定ファイルからのメタデータ読み込み
on readMetadataFrom(imageFile)
load framework
set {theRecord, theError} to SMSForder's metadataFromImage:imageFile |error|:(specifier)
if theRecord = missing value then -- there was a problem, so extract the error description
error (theError's localizedDescription() as text) -- number (theError's code())
else
return theRecord
end if
end readMetadataFrom
--日付文字列を形式指定しつつdate objectに変換
on dateFromStringWithDateFormat(dateString, dateFormat)
set dStr to NSString's stringWithString:dateString
set dateFormatStr to NSString's stringWithString:dateFormat
set aDateFormatter to NSDateFormatter's alloc()'s init()
aDateFormatter's setDateFormat:dateFormatStr
aDateFormatter's setLocale:(NSLocale's alloc()'s initWithLocaleIdentifier:"en_US_POSIX")
set aDestDate to (aDateFormatter's dateFromString:dStr)
return aDestDate as any
end dateFromStringWithDateFormat
Your approach seems far from the correct answer.
My AppleScript works on macOS 13.3beta now.
use AppleScript version "2.8"
use scripting additions
use framework "Foundation"
use framework "PDFKit"
property kCGPDFContextOwnerPassword : a reference to current application's kCGPDFContextOwnerPassword
property NSDictionary : a reference to current application's NSDictionary
property kCGPDFContextUserPassword : a reference to current application's kCGPDFContextUserPassword
property |NSURL| : a reference to current application's |NSURL|
property PDFDocument : a reference to current application's PDFDocument
set userPassword to "12345"
set ownerPassword to "01234"
set aPath to (choose file of type {"com.adobe.pdf"} with prompt "Select PDF to Encrypt")
set newF to choose file name with prompt "Select path & file name of password protected PDF"
set aRes to my encryptPDF(aPath, newF, ownerPassword, userPassword)
on encryptPDF(aPath, newF, ownerPassword, userPassword)
set aURL to |NSURL|'s fileURLWithPath:(POSIX path of aPath)
set aPDFdoc to PDFDocument's alloc()'s initWithURL:aURL
set anEncF to aPDFdoc's isEncrypted()
--Not encrypted
if anEncF = false then
set newFp to POSIX path of newF
if newFp does not end with ".pdf" then
set newFp to newFp & ".pdf"
end if
(*
CFStringRef kCGPDFContextAuthor;
CFStringRef kCGPDFContextCreator;
CFStringRef kCGPDFContextTitle;
CFStringRef kCGPDFContextOwnerPassword;
CFStringRef kCGPDFContextUserPassword;
CFStringRef kCGPDFContextAllowsPrinting;-
CFStringRef kCGPDFContextAllowsCopying;--boolean CFStringRef kCGPDFContextOutputIntent;-
CFStringRef kCGPDFContextOutputIntents;
CFStringRef kCGPDFContextSubject;
CFStringRef kCGPDFContextKeywords;
CFStringRef kCGPDFContextEncryptionKeyLength;
*)
set aDic to NSDictionary's dictionaryWithObjects:{ownerPassword, userPassword} forKeys:{kCGPDFContextOwnerPassword, kCGPDFContextUserPassword}
set aRes to aPDFdoc's writeToFile:newFp withOptions:aDic
return aRes as boolean
else
--Already Encrypted
return false
end if
end encryptPDF
Hi,
How do you get the path data?
I got my selected file track on my Music.app by simple AppleScript.
tell application "Music"
set aList to selection
set aTrack to first item of aList
location of aTrack
end tell
This script returns alias type data. AppleScript's native path format is alias.
Each file track has "location" property and it is not read only. It is change-able property.
http://piyocast.com/as/wp-content/uploads/2023/03/music_dict_part.png
So you will be able to select new location to each missing file tracks.
One track is a piece of cake. 5,000?
Hmm...we have to take other approarch. We can write fixing AppleScript. But it requires remote checking and specification document....I will do that work on condition that I get paid for it.
Did you set up Safari to execute "do javascript" AppleScript command?
tell application "Safari"
make new document with properties {URL:"http://piyocast.com/as"}
end tell
If this script works, AppleScript itself works with Safari.
tell application "Safari"
set aRes to do JavaScript "var selObj = window.getSelection();
var selStr = (selObj).getRangeAt(0);
unescape(selStr);" in front document
end tell
display dialog aRes
If this script does not work, you have to allow Safari to execute "do JavaScript" command.
Safari v10 or later exhibit to execute "do JavaScript" command by default.
You have to enable "Develop" menu from Safari's preferences setting.
And....execute "Allow JavaScript from Apple Events" command from Safari'sDevelop menu (this operation require admin password).
I wrote an ebook about 7 AppleScript-able web browser scripting (PDF 330pages).
Scripting about Safari, Google Chrome, Chromium, Microsoft Edge, Vivaldi, Brave Browser and Opera.
https://piyomarusoft.booth.pm/items/3664077
I wrote about this issue in my ebook.
Yes. You're right. I did.
You can call the framework call YOLOv3.mlmodel from AppleScript.
I called self-made mlmodel like this.
http://piyocast.com/as/archives/4853