# Using Save() and exporting application macOS

**URL:** <https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549>\
**Category:** Processing.py\
**Created:** [April 8, 2020, 4:18pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549 "2020-04-08T16:18:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 8, 2020, 4:18pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/1 "2020-04-08T16:18:26Z")

</div>

I have used save() in my code to save images of the window to the sketch folder as a ‘screenshot’ function and have exported my program to an application.  
When I run the application and tried to screenshot the image is not saved.

I have also tried saving the images to a data folder and adding a data folder to the application folder but this also doesn’t work.

Is it possible to save images from the application?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 16, 2020, 3:13pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/2 "2020-04-16T15:13:09Z")

</div>

Were you able to resolve this?

It sounds like you might be trying to saving files inside the app itself. What OS are you building / testing on? Have you tried a relative path outside the sketch, or an absolute path like the user Documents folder?

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 16, 2020, 6:35pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/3 "2020-04-16T18:35:20Z")

</div>

Thanks for your reply, it works when I use an absolute path however doesn’t seem to work using a relative path. I will be distributing the app to other people so I don’t know how this will work if I can only use an absolute path? I am on macOS.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 16, 2020, 9:49pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/4 "2020-04-16T21:49:39Z")

</div>

Here is a test sketch that may help you narrow down what is happening.

```auto
/**
 * SaveExport -- exported app saving path tests
 * 2020-04 Jeremy Douglass -- Processing 3.4 macOS 10.12
 * 1. a red image appears in the /data subfolder
 * 2. blue and green images appear in the same folder as the app
 * 3. yellow and cyan images appear in the folder above the app (../)
 */
void setup(){
  println(sketchPath());
}

void draw(){
  if(frameCount==1){
    background(255,0,0);
    saveFrame("data/red-data.png");
  }
  if(frameCount==2){
    background(0,255,0);
    println("green-inside.png");
    saveFrame("green-inside.png");
  }
  if(frameCount==3){
    background(0,0,255);
    println(sketchPath() + "/blue-abs-inside.png");
    saveFrame(sketchPath() + "/blue-abs-inside.png");
  }
  if(frameCount==4){
    background(255,255,0);
    saveFrame("../yellow-rel-outside.png");
  }
  if(frameCount==5){
    background(0,255,255);
    println(sketchPath() + "/../cyan-abs-rel-outside.png");
    saveFrame(sketchPath() + "/../cyan-abs-rel-outside.png");
  }
}

```

---

<div class="post-metadata">

**Author:** ![poboyd](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/poboyd/32/8908_2.png) [@poboyd](https://discourse.processing.org/u/poboyd)\
**Post date:** [April 17, 2020, 8:01am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/5 "2020-04-17T08:01:44Z")

</div>

have you tried the java function…

String applicationPath = System.getProperty(“user.dir”);

This is a platform independent method so works on windows and mac.

You could print out the applicationPath to see where the application thinks its home is, I use it in PoShowTube to get to my data folder…

String dataFolderPath = System.getProperty(“user.dir”) + “/data”;

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 17, 2020, 8:53am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/6 "2020-04-17T08:53:58Z")

</div>

Thank you for this. I forgot to say I am using Python mode and have converted your code to Python which works when running it in Processing but doesn’t work when I export it to an app. It seems that the sketchPath() is not defined properly for the Python app as when I print it out it just returns ‘/’. I’m not sure why this is happening, do I need to set the sketchPath() somewhere?

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 17, 2020, 8:56am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/7 "2020-04-17T08:56:06Z")

</div>

Sorry I forgot to mention I am using Python mode, is there a Python equivalent to this?

---

<div class="post-metadata">

**Author:** ![poboyd](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/poboyd/32/8908_2.png) [@poboyd](https://discourse.processing.org/u/poboyd)\
**Post date:** [April 17, 2020, 9:17am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/8 "2020-04-17T09:17:24Z")

</div>

not sure im afraid, theres this on stackoverflow

> <https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python>

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 17, 2020, 9:23am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/9 "2020-04-17T09:23:29Z")

</div>

Okay thanks I’ll take a look

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 18, 2020, 8:13pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/10 "2020-04-18T20:13:26Z")

</div>

On Linux `sketchPath()` worked OK in the exported Python mode app. I’ll see if I can test on MacOS and get back to you.

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0f1239ae69a73a9ee631220e809f73a3f7752ece.png)

UPDATE: On my MacOS I can run the same sketch but the exported app just won’t launch! :(((  
SECOND UPDATE: Chosing the 'Add Java" option worked,

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e1057ef46f577320c00bbab659c4d55a095fc46c.png)

Looks like `sketchPath()` worked. Can you check if it is something else?

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 19, 2020, 8:21am UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/11 "2020-04-19T08:21:47Z")

</div>

I’m not sure why but when I exported the app with ‘Full Screen (Present Mode)’ selected, sketchPath() didn’t work but when I exported the app without this chosen, it worked.  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 19, 2020, 4:44pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/12 "2020-04-19T16:44:58Z")

</div>

Good that it helped!

Curious that you mentioned Full Screen (Present Mode) is behaving differently.  
I think I should add this to:

> <https://github.com/jdf/processing.py/issues/356>
>
> On Mac OS, Processing 3.5.4, Processing Mode 3056, exporting an application with
> "Full Screen (present mode)" checkbox at the export panel does...

---

<div class="post-metadata">

**Author:** ![mpsftw](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mpsftw/32/8912_2.png) [@mpsftw](https://discourse.processing.org/u/mpsftw)\
**Post date:** [April 20, 2020, 2:36pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/13 "2020-04-20T14:36:06Z")

</div>

It seems to work fine on my version, with the present mode bug fixed.

Tested with the following:

```auto
def setup():
    size(800,800)
    text(sketchPath(),20,20)
    
def draw():
    if (frameCount==1):
        background(255,0,0)
        text(sketchPath(),20,20)
        saveFrame("data/red-data.png")
    if (frameCount==2):
        background(0,255,0)
        text(sketchPath(),20,20)
        saveFrame("green-inside.png")
    if (frameCount==3):
        background(0,0,255)
        text(sketchPath(),20,20)
        saveFrame(sketchPath() + "/blue-abs-inside.png")

```

It works with and without present mode selected:

```auto
Mollys-iMac:MacOS molly$ find .. -name "*.png"
../Processing/green-inside.png
../Processing/blue-abs-inside.png
../Processing/lib/jycessing/splash.png
../Processing/data/red-data.png

```

---

<div class="post-metadata">

**Author:** ![mpsftw](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mpsftw/32/8912_2.png) [@mpsftw](https://discourse.processing.org/u/mpsftw)\
**Post date:** [April 20, 2020, 2:43pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/14 "2020-04-20T14:43:27Z")

</div>

I’ll add that the sketchPath() is INSIDE the app, so from the finder you have to Show Package Contents to find the saved files.

 ![Screen Shot 2020-04-20 at 9.42.43 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/64f516c4933e21b91a08b8fd6ba6eefa5655193f.png)

---

<div class="post-metadata">

**Author:** ![mpsftw](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mpsftw/32/8912_2.png) [@mpsftw](https://discourse.processing.org/u/mpsftw)\
**Post date:** [April 20, 2020, 5:13pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/15 "2020-04-20T17:13:19Z")

</div>

Considering your intended goal of exporting a distributable app, you might want to consider using selectFolder() instead of trying to find a path, so the user can select the save path themselves:

```auto
savedir = None
frame=0

def setup():
    size(800,800)
    selectFolder("Select a directory to save to", "fileSelected")
    
def fileSelected(selection):
    global savedir
    println(selection.getAbsolutePath())
    savedir = selection.getAbsolutePath()
    
def draw():
    # selectFolder is async so frameCount won't work
    global frame
    global savedir
    background(0)
    if savedir is not None:
        frame=1
    if (frame==1):
        background(255,0,0)
        text(savedir,20,20)
        saveFrame(savedir + "/data/red-data.png")
        frame+=1
    if (frame==2):
        background(0,255,0)
        text(savedir,20,20)
        saveFrame(savedir + "/green-inside.png")
        frame+=1
    if (frame==3):
        background(0,0,255)
        text(savedir,20,20)
        saveFrame(savedir + "/blue-abs-inside.png")
        frame+=1

```

Here’s another alternative that uses a platform independent way to generate a save path:

```auto
from os.path import expanduser

savedir = None
frame=0

def setup():
    global savedir
    size(800,800)
    savedir = getSaveDir()
    println(savedir)
    
def draw():
    # selectFolder is async so frameCount won't work
    global frame
    global savedir
    background(0)
    if savedir is not None:
        frame=1
    if (frame==1):
        background(255,0,0)
        text(savedir,20,20)
        saveFrame(savedir + "/data/red-data.png")
        frame+=1
    if (frame==2):
        background(0,255,0)
        text(savedir,20,20)
        saveFrame(savedir + "/green-inside.png")
        frame+=1
    if (frame==3):
        background(0,0,255)
        text(savedir,20,20)
        saveFrame(savedir + "/blue-abs-inside.png")
        frame+=1
        
def getOsVersion():
    ver = sys.platform.lower()
    if ver.startswith('java'):
        import java.lang
        ver = java.lang.System.getProperty("os.name").lower()
    return ver

def getSaveDir():
    savedir=expanduser("~")
    ver=getOsVersion()
    if (ver == "mac os x"):
        savedir+="/Documents/sketchPathTest"
    # Other os tests go here
    return savedir

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 20, 2020, 6:10pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/16 "2020-04-20T18:10:20Z")

</div>

Oh, this is just brilliant! Thank you for sharing it here!

---

<div class="post-metadata">

**Author:** ![sarina](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sarina](https://discourse.processing.org/u/sarina)\
**Post date:** [April 20, 2020, 6:41pm UTC](https://discourse.processing.org/t/using-save-and-exporting-application-macos/19549/17 "2020-04-20T18:41:15Z")

</div>

This is just what I needed, thanks for your help!
