Sunday, December 4, 2022

#1 2022-11-03 11:53:05 am

istarhan
Member
Registered: 2020-03-20
Posts: 10

How to call an image from Xcode assets

Hello everyone,

I am trying to code an Apple Script App in Xcode for sending automated e-mails.

I need to add multiple images to email body. Since the app will be used by multiple users, I also need to add images with relative links.

However, I am not sure how to do this. Is it possible to call images from Xcode assets? or is there any other easier way to do this?

Thank you all in advance?

Model: MBP M1 Pro 2021
AppleScript: XCode 14 - Apple Script template is taken from Xcode 13
Browser: Safari 605.1.15
Operating System: macOS 13

Last edited by istarhan (2022-11-04 03:28:23 pm)

Offline

 

#2 2022-11-04 05:46:12 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: How to call an image from Xcode assets

I'm not a Xcode expert but...
https://developer.apple.com/documentati … de-project

And use NSImage(named: "ImageName") in your ASObjC


Node-RED makes it easy to automate IoT

Offline

 

#3 2022-11-04 03:32:23 pm

istarhan
Member
Registered: 2020-03-20
Posts: 10

Re: How to call an image from Xcode assets

Hello @Fredrik71,

Thank you so much for your response.

The source you provided suggests:

let image = NSImage(named: "ImageName")

So if I have three images to add, should I use

let imageA = NSImage(named: "Image-Top")

let imageB = NSImage(named: "Image-Middle")

let imageC = NSImage(named: "Image-Bottom")

then call variables imageA, imageB, and imageC later in e-mail body?

Regards,

Offline

 

#4 2022-11-04 05:45:46 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: How to call an image from Xcode assets

istarhan wrote:

The source you provided suggests:
let image = NSImage(named: "ImageName



Not exatly... that is Swift programming language....
You need ASObjC and that is AppleScript + Objective-C

Something like this...
set theImage to current application's NSImage's imageNamed:"YOUR_IMAGE_NAME"

NSImage is class and imageName is type method. In AppleScript you use current application to call class name. You could find many examples for NSImage class in this forum.

Last edited by Fredrik71 (2022-11-04 05:49:53 pm)


Node-RED makes it easy to automate IoT

Offline

 

#5 2022-11-08 11:02:56 pm

technomorph
Member
Registered: 2017-12-14
Posts: 304

Re: How to call an image from Xcode assets

Yes it’s important when your reading any developer documentation to
Make sure it’s in showing Objective-C code.

“Let” is a Swift command.

Offline

 

#6 2022-11-09 11:30:18 am

istarhan
Member
Registered: 2020-03-20
Posts: 10

Re: How to call an image from Xcode assets

Hello again,

Somehow Xcode 14 does not allow me to assign actions to "sender"

Thus, I decided to create a simple Automator script.

However, I could not figure out how to assign an online image source (the image file is located in a shared cloud storage folder) to a variable.

Any help much appreciated.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)