Save .txt file to desktop Mac

Hi all,

I want to save the .txt file my processing sketch outputs directly to a mac desktop. Can you suggest how I’d do that? I assume it’s within createWriter(), but I don’t know how to signify a path on mac. Here’s my sketch:

PrintWriter output;

int count = 0;
int x = 0;
int y = 0;
int i=0;
int timer = 0;
float m;

ArrayList xp = new ArrayList();
ArrayList yp = new ArrayList();

void setup(){
  output = createWriter("coordinates.txt");
  size(400,400, P3D); 
  background(0);  
  noFill();
  stroke(255);
  strokeWeight(1);
  
}

void draw(){
  background(0);
  
  int sx,ex,sy,ey;
  float z = 0;
  xp.add(mouseX);
  yp.add(mouseY); 
  if(xp.size() > 1){
    for(int i = xp.size()-1 ; i > 0 ; i--){
  sx = (Integer) xp.get(i);
  ex = (Integer) xp.get(i-1);
  sy = (Integer) yp.get(i);
  ey = (Integer) yp.get(i-1);
  line(sx,sy,z,ex,ey,z-1);
  z -= -.1;
}
 
//    output.println ("x=" + mouseX);
//    output.println ("y=" + mouseY);
//    output.println ("z=" + z);
  } 
  output.println(mouseX+","+mouseY+","+z);
}

void keyPressed(){ 
    output.flush();
    output.close();
    exit();
}
1 Like

On your Mac, open Terminal.

> cd Desktop
> pwd
/Users/jeremydouglass/Desktop
> touch afile.txt

Now there is a file at:

/Users/jeremydouglass/Desktop/afile.txt