I have a simple Swift-based macOS app that creates and executes an Apple Script:let unreadEmailsScript = """
tell application "Mail"
get unread count of inbox
end tell
"""
if let scriptObject = NSAppleScript(source: unreadEmailsScript) {
var errorDict: NSDictionary? = nil
scriptObject.executeAndReturnError(&errorDict)
if let error = errorDict {
print(error)
}
}I've added the following to my project's entitlements:<key>com.apple.security.temporary-exception.apple-events</key> <array> <string>com.apple.Mail</string></array>When I execute this on the latest version (18A389) of Mojave the code prints:{
NSAppleScriptErrorAppName = Mail;
NSAppleScriptErrorBriefMessage = "Not authorized to send Apple events to Mail.";
NSAppleScriptErrorMessage = "Not authorized to send Apple events to Mail.";
NSAppleScriptErrorNumber = "-1743";
NSAppleScriptErrorRange = "NSRange: {33, 12}";
}The system doesn't prompt me for authorization at app launch.What is the correct way to send Apple Events to Mail via a Swift app under Mojave?TIA
Post
Replies
Boosts
Views
Activity
Thank you in advance!
I'm working with Apple's sample code for PhotoBrowse.
In the main view controller's viewDidLoad() method we have this code:
let allPhotosOptions = PHFetchOptions()
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
This code sorts the photos by "creationDate". How do I determine/find the other valid values for these sort descriptors? For example, what if I wanted to sort photos by their file size, last modified date, etc.?
TIA!
It is 2023 and Photos.app still provides no way to sort photos/movies by file size.
I ended up writing some AppleScript that displays the file sizes of images/movies in a specific album. It is also simple to create a shell script to examine the photo library contents directly but mapping the UUID-based filenames back to the names used in Photos.app is not straightforward (to me at least).
You can't even create a smart album based upon file size.
Why is there no native support for this in Photos.app/PhotoKit?
(And, yes, I have submitted many feature requests over the years)
I wrote a Python script that iterates over all the "Junk.mbox" folders in my account (/Users/Bob/Library/Mail). My account, Bob, is an admin account. Even if I run my script with sudo, the script fails with a permissions error. I manually checked ALL of the folders (recursively) in /Users/Library/Bob/Mail and they all have read/write access for my account.
I wondered if it was SIP related so I disabled it. And, yes, I can access that folder programmatically with SIP disabled. So I re-enabled SIP and simply copied the contents of /Users/Bob/Library/Mail to ~/tmp. Now my Python script runs without issue when pointing to that folder.
Please tell me that I don't have to disable SIP or copy gigabytes worth of data to another location just to access my own email data.
Any suggestions would be greatly appreciated!