# Open picture file with mail (to be attachment)

**URL:** <https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186>\
**Category:** General\
**Created:** [August 23, 2021, 8:25pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186 "2021-08-23T20:25:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gijs\_Raggers](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gijs\_Raggers](https://forum.xojo.com/u/Gijs_Raggers)\
**Post date:** [August 23, 2021, 8:25pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/1 "2021-08-23T20:25:11Z")

</div>

Hello, I would like to open a picture file with mail, to be an attachment. Used to work in the old days. Example below opens the png file in Preview. Suggestions to open it with Mail?

Var fApp As FolderItem  
Var fDoc As FolderItem

fApp=SpecialFolder.Applications.child(“Mail.app”)  
fDoc=app.theTemp.Child(“picTemp.png”)  
thePicTape.Save(fDoc, Picture.Formats.PNG)  
fDoc.Open(fApp.NativePath,True)

Manual says: **FolderItem.Open** (parameters As String = “”, activate As Boolean = True)  
_parameters_ is the app’s parameters to be passed to the app being open.

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [August 24, 2021, 4:16pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/2 "2021-08-24T16:16:33Z")

</div>

> [@Gijs\_Raggers](#):
>
> **Open**

it opens the app for file with this extension  
so if folderitem is a .pdf it opens a registered pdf viewer  
if folderitem is a .html it open the default browser.

somehow you open a picture and give the paint app the fApp path.

---

<div class="post-metadata">

**Author:** ![Gijs\_Raggers](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gijs\_Raggers](https://forum.xojo.com/u/Gijs_Raggers)\
**Post date:** [August 24, 2021, 4:59pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/3 "2021-08-24T16:59:35Z")

</div>

Open command replaced launch. Launch could open a file with an app you choose. It this option gone now?

---

<div class="post-metadata">

**Author:** ![Jürg\_Otter](https://forum.xojo.com/user_avatar/forum.xojo.com/j%C3%BCrg_otter/32/584_2.png) [@Jürg\_Otter](https://forum.xojo.com/u/J%C3%BCrg_Otter)\
**Post date:** [August 24, 2021, 5:33pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/4 "2021-08-24T17:33:38Z")

</div>

> [@Gijs\_Raggers](#):
>
> file with mail, to be an attachment  
> fApp=SpecialFolder.Applications.child(“Mail.app”)

On macOS, use `NSSharingService`.  
Example project: [NSSharingService example](https://www.jo-tools.ch/xojo/nssharingservice/)

And don’t assume that every macOS user is using Mail.app.  
[NSSharingService (Apple Developer Documentation)](https://developer.apple.com/documentation/appkit/nssharingservice) _should_ take care of that, too.

---

<div class="post-metadata">

**Author:** ![Gijs\_Raggers](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gijs\_Raggers](https://forum.xojo.com/u/Gijs_Raggers)\
**Post date:** [August 24, 2021, 6:28pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/5 "2021-08-24T18:28:12Z")

</div>

> [@Jürg\_Otter](#):
>
> On macOS, use `NSSharingService`.  
> Example project: [NSSharingService example](https://www.jo-tools.ch/xojo/nssharingservice/)

Thanks Jurg, I will try this.  
Still I would like to know if Xojo can open a file with a specific app like it used to.

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [August 24, 2021, 7:03pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/6 "2021-08-24T19:03:07Z")

</div>

this open Mozilla Thunderbird Mailer with Text File as Attachment

```auto
Var a As FolderItem = New FolderItem("C:\Program Files\Mozilla Thunderbird\thunderbird.exe",FolderItem.PathModes.Native)
a.Open(Encodings.UTF8.Chr(34)+"C:\Users\Markus\Desktop\Neues Textdokument.txt"+Encodings.UTF8.Chr(34))

```

i used “” around because space in path. without “” the space would be a argument separator.

your problem is the mixed up fDoc & fApp  
u will open the app with the pic as argument.

i think  
`fDoc.Open(fApp.NativePath,True)`  
should be  
`fApp.Open(fDoc.NativePath,True)`

---

<div class="post-metadata">

**Author:** ![Jürg\_Otter](https://forum.xojo.com/user_avatar/forum.xojo.com/j%C3%BCrg_otter/32/584_2.png) [@Jürg\_Otter](https://forum.xojo.com/u/J%C3%BCrg_Otter)\
**Post date:** [August 24, 2021, 7:48pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/7 "2021-08-24T19:48:49Z")

</div>

I’m still having macOS in mind in this reply…

> [@Gijs\_Raggers](#):
>
> Still I would like to know if Xojo can open a file with a specific app like it used to.

In theory and according to Xojo’s Documentation this should work _(assuming the .app you’re launching is accepting a parameter, which is a shell path to a file that it’s going to open)_:

`fApp.Open(fDoc.ShellPath, True)`

If that doesn’t work, another option would be to use a `Shell` _(same assumption as above regarding parameters)_:

```auto
Dim s As New Shell
s.Execute("open -n " + fApp.ShellPath + " " + fDoc.ShellPath)

```

Having said that, just another thing to keep in mind:

> [@Gijs\_Raggers](#):
>
> fApp=SpecialFolder.Applications.child(“Mail.app”)

That most likely won’t work on the latest macOS Versions. System Applications are located in a different folder/volume. You shouldn’t try to locate an .app like this, but ask the OS where to find the app with a specific BundleID (in your example this would be: `com.apple.mail`).  
Here is an example project that shows how to find an .app by BundleID, list all possible “Application Directories”, list all applications that can deal with a given file: [App Directories example](https://www.jo-tools.ch/xojo/app-directories/)

---

<div class="post-metadata">

**Author:** ![Jürg\_Otter](https://forum.xojo.com/user_avatar/forum.xojo.com/j%C3%BCrg_otter/32/584_2.png) [@Jürg\_Otter](https://forum.xojo.com/u/J%C3%BCrg_Otter)\
**Post date:** [August 24, 2021, 8:12pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/8 "2021-08-24T20:12:51Z")

</div>

> [@Jürg\_Otter](#):
>
> In theory and according to Xojo’s Documentation this should work _(assuming the .app you’re launching is accepting a parameter, which is a shell path to a file that it’s going to open)_:
> 
> `fApp.Launch(fDoc.ShellPath, True)`

I’ve just tried this quickly on macOS Big Sur.

- fApp: `/System/Applications/Preview.app`
- fDoc: `/path/to/a/picture.png`

Code:

```auto
fApp.Open(fDoc.ShellPath, True) [2021r2.1]
fApp.Launch(fDoc.ShellPath, True) [2021r2.1, 2018r4]

```

- works as expected when built with Xojo 2018r4
- just opens Preview.app (which is asking for a file to be opened) when built with Xojo 2021r2.1

Makes me think that the revamped `FolderItem` _(Xojo 2019r2: FolderItem updated to use latest OS APIs on macOS)_ is still not working as expected for this situation ☹  
If so… then `Shell` should be an alternative.

---

<div class="post-metadata">

**Author:** ![Gijs\_Raggers](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gijs\_Raggers](https://forum.xojo.com/u/Gijs_Raggers)\
**Post date:** [August 24, 2021, 8:47pm UTC](https://forum.xojo.com/t/open-picture-file-with-mail-to-be-attachment/65186/9 "2021-08-24T20:47:24Z")

</div>

Only just saw and downloaded your [NSSharingService example](https://www.jo-tools.ch/xojo/nssharingservice/). Looks great! Trying tomorrow.
