Mac Mini Seq Ver 15.7.3 with latest XOJO
I built a simple Applescript (below) that opens a file, saves it as a Numbers file and adds a password to the numbers file. It works great on its own. I dragged it into my XOJO app and am trying to run from within XOJO. However, it only partially works. It will open Numbers and bring in the data, but it will not add the password or save the file, it just leaves the Numbers window open.
Am I missing something to get this to work? Will it work? My requirements are no additional plugins to XOJO, or any changes that would require (e.g. plist changes etc) modifications to the MACs of the other three users that use my app.
Or is there a way to execute this script from XOJO, without it being in XOJO?
Thanks for any insights or help?
set csvFile to POSIX file “/Users/Home/Desktop/My Text Out.txt”
set saveFile to POSIX file “/Users/Home/Desktop/joe.numbers”
tell application “Numbers”
set doc to open csvFile
set password “jim” to first document
save doc in saveFile
close doc
end tell
You have to have entitlements for any app that uses AppleScripts. Actually, you even have to build your app and have the permissions set correctly or it won’t even work on your own computer.
Thanks. Before I abandon this, do you have any (simple) recommendation that i can possibly use to do this? Thanks.
The entitlements part really takes away from the simple aspect. Beatrix has shared example code a dozen times over and it’s never read like it’s complicated.
I’m not suggesting you have to go search for it, just trying to provide context for:
Which is the part that’s not simple enough for you?
Code we may be able to simplify, but the code signing and entitlements we can’t really do anything about.
Thanks. I’ve never done any code signing and entitlements. XOJO is just a hobby for me and I really dont want to get into anything above simple XOJO coding that may cause any issues with what I have done, or to the couple other users that use my app.
That is understandable. Entitlements suck and codesigning sucks even more. I spent an hour or so last summer to get the entitlements for the Contacts right and I know about that stuff.
Can you share what you are trying to do? The key problem is the password. You can easily do a csv file without a password.
My goal was to output a password protected file from my XOJO app.
I finally got my Applescript to work as I wanted. The applescript takes a text output file (semi colon delimited) from my XOJO app and opens it in “Numbers”, adds a password to the file, and saves it as a “Numbers” file. It then Renames the file with a leading “Date” (so I know when it was created) and moves it to a specified folder. I was hoping to do this easily within my XOJO app, but it turns out that wasn’t as easy as i hoped. So in the end I just need to run my applescript “app” outside of my XOJO app.
Thanks again for all your thoughts and comments.
Honestly, this is where AppleScript really shines: a quick way to get something complex done when an app doesn’t make it easy.
I suppose you wrote your Script using the Script Editor application:
it is located in the Applications → Utilities folder.
Then, when you run it there it works fine.
Your actual problem is to run it inside Xojo.
Am I right ?
Correct. Script runs fine on its own. However if I try to run it from within XOJO, it stops after opening “Numbers”.
I think all you need to do is add the AppleEvent entitlement to your app’s .plist. And that .plist is embedded in the built app, your other users don’t have to do a thing.
I just took your AppleScript (slightly modified for pathnames) and added it to a new project. I created a .plist entitlement key NSAppleEventsUsageDescription and added an explanation string for the value. Finally, I created a CSV text file on the Desktop. Nothing else. I ran the project, was asked to allow the app to access Numbers, and a new CSV text file named “Joe” was created and password protected with the word “Jim”.
This is on macOS 26.2 Tahoe.
Once you codesign the app, I don’t see why this wouldn’t work for your other users.
1 Like
WOW! Jonathan, it worked!!
I added my applescript to my project. Went under “Build Settings”, macOS/Property List/Edit.
I added a string key “NSAppleEventsUsageDescription” and a value “This app requires access to send commands to other applications.”
And It Works! I can now run my applescript from with my XOJO app!
On first run I get alot of “Allow” windows, but on subsequent runs I only get this once, or sometimes not at all.
Mac running 15.7.3
XOJO 3.1