# How to get the sketch title (or tab title) from within a sketch?

**URL:** <https://discourse.processing.org/t/how-to-get-the-sketch-title-or-tab-title-from-within-a-sketch/39057>\
**Category:** Beginners\
**Created:** [October 3, 2022, 3:16pm UTC](https://discourse.processing.org/t/how-to-get-the-sketch-title-or-tab-title-from-within-a-sketch/39057 "2022-10-03T15:16:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulwb](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@paulwb](https://discourse.processing.org/u/paulwb)\
**Post date:** [October 3, 2022, 3:16pm UTC](https://discourse.processing.org/t/how-to-get-the-sketch-title-or-tab-title-from-within-a-sketch/39057/1 "2022-10-03T15:16:00Z")

</div>

I want to uniquely name the images I save from my sketch, so I can figure out what particular p5js sketch made what image. To do this, I need to determine the sketch name from within the sketch.

I don’t want to type the sketch name into each sketch as a variable; I want to programmatically obtain it. That way I can write my own image-saving function that makes a fancy filename with the sketch name, the date, and time, and so on, and reuse it in every sketch I write.

How can I do this?

Attempt 1:

Poking around in the Chrome dev tools, I was able to find an element that contains the sketch name. But I have not been able to access it using selectAll(), or by rewriting the sketch to use instantiation mode, and then trying to use document.querySelector(). It seems like all that’s available for both of these is the very basic HTML document that the script loads into, not the full rendered page on p5.js.

The relevant line is:

```auto
<input type="text" maxlength="128" class="toolbar__project-name-input" aria-label="New sketch name" value="MY_SKETCH_NAME">

```

Maybe this is because the sketch is loaded into an iframe? And I would need to access the parent iframe? As you can probably tell I have no experience with any of this, so help would be appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 4, 2022, 8:06am UTC](https://discourse.processing.org/t/how-to-get-the-sketch-title-or-tab-title-from-within-a-sketch/39057/2 "2022-10-04T08:06:40Z")

</div>

Hi @paulwb,

Welcome to the community! 😉

> [@paulwb](#):
>
> I need to determine the sketch name from within the sketch.

What is `sketch name` referring to? The browser tab title? The `.js` sketch filename?

If you are looking for the tab title, just use the `document.title` JS property:

> **[Document: title property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/title)**
>
> The document.title property gets or sets the current title of the document.
> When present, it defaults to the value of the .

If you are looking for the JS script filename:

> <https://stackoverflow.com/questions/710957/how-might-i-get-the-script-filename-from-within-that-script/10656401#10656401>
