AppleScript on Xcode (14.2)

Is there any way to make a AppleScript only app using Xcode 14.2.

My AppleScript only I mean use it to handle both the function and UI.

Here is an example AppleScript that I hope I can package into an Xcode project and release as an app.

set userEmail to ""
display dialog "Please enter your email address:" default answer "" buttons {"Cancel", "OK"} default button 2
set userEmail to text returned of the result
set chosenFile to choose file with prompt "Please select a file:"
set fileAddress to POSIX path of chosenFile
set AppleScript's text item delimiters to "/"
set fileComponents to text items of fileAddress
set parentFolderComponents to items 1 through -2 of fileComponents
set parentAddress to (parentFolderComponents as text) & "/"
tell application "Terminal"
	activate
	delay 2
	do script "cd " & quoted form of parentAddress & "; gpg --local-user " & quoted form of userEmail & " --clearsign " & quoted form of fileAddress & "; gpg --local-user " & quoted form of userEmail & " --detach-sign " & quoted form of fileAddress & "; exit"
end tell

Thank you.

MacBook Pro 13″, macOS 12.6

Posted on Jun 24, 2023 4:44 PM

Reply
3 replies

Jun 24, 2023 7:13 PM in response to SHA-512

Okay, seems you’re asking for an email address and some file to send… correct?


Xcode isn’t the usual tool for AppleScript. And AFAIK, Xcode 14 doesn’t support AppleScript editing.


Seems this is mailing the file using (!?) gpg? You’ll need to install and configure gpg, as that’s not part of macOS.


Alternatives include using the command-line mailx command, or using AppleScript to script Mail app. And if you use mailx, there’ll be some configuration there, and you’ll need to MIME encode the files as attachments as the macOS version of mailx doesn’t support the -a MIME-encoded attachment switch.


Depending on what you’re after more generally, Swift or bash or zsh or Python can also work. Apple does have mail-related framework around, which makes that easier for Swift or Objective C or such. Python is still around, but Apple is removing it.


You’ll want to test this with app bundles and whatever else somebody will specify as an input file to this app, too.

Jun 25, 2023 12:12 PM in response to SHA-512

if you can use mail messages with MIME attachments, and depending on the particular encryption requirements, I’d probably use the built-in file encryption LibreSSL with either symmetric or asymmetric encryption. Or would use the built-in S/MIME.


I’d likely also use either a shell script or an app for this, if not the built-in S/MIME support. (I’m also not hugely fond of using AppleScript outside of scripting GUI apps, so my opinion here is not without coloration.)


If S/MIME is an option (for the recipient), the Mac Mail app supports that natively. Here is some Apple doc:

Use S/MIME to send and receive encrypted messages in the Mail app in iOS - Apple Support


The following S/MIME setup is from a certificate vendor:

https://www.ssl.com/how-to/installing-an-s-mime-certificate-and-sending-secure-email-in-macos/

Using your own private CA is also feasible, if you have a trusted path to distribute the public key to recipients.


If not S/MIME, then here’s how to use the built-in LibreSSL in Ventura that’s available in bash, zsh, and otherwise, encrypting and decrypting with AES 256 CBC symmetric encryption:


$ openssl version
LibreSSL 3.3.6
$ echo "Hello, New England" >>  in.txt
$ openssl enc -aes-256-cbc -salt -in in.txt -out enc.dat
enter aes-256-cbc encryption password:password123
Verifying - enter aes-256-cbc encryption password:password123
$ openssl enc -d -aes-256-cbc -in enc.dat -out out.txt
enter aes-256-cbc decryption password:password123
$ cat out.txt
Hello, New England
$

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript on Xcode (14.2)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.