src/docs/src/Perms/requestWriteDesktop.md
Request write access to the user's Desktop folder. If the user has already granted this permission the user will not be prompted and the path will be returned. If the user grants permission the path will be returned. If the user does not allow access undefined will be returned.
On a website, sign the user in to your site first with puter.auth.signIn(). This method reads the signed-in user's identity before it can prompt, so for a signed-out visitor it rejects with Unauthorized and no prompt is shown. Answering a permission prompt does not by itself sign the user in to your site, so guard the call:
if (!puter.authToken) await puter.auth.signIn();
puter.perms.requestWriteDesktop()
None
A Promise that resolves to:
string - The Desktop folder path if permission is grantedundefined - If permission is denied<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-desktop">Request Desktop Write Access</button>
<script>
document.getElementById('request-desktop').addEventListener('click', async () => {
const desktopPath = await puter.perms.requestWriteDesktop();
if (desktopPath) {
puter.print(`Desktop path: ${desktopPath}`);
// Now you can write files to the Desktop
await puter.fs.write(`${desktopPath}/my-file.txt`, 'Hello from Desktop!');
puter.print('File written to Desktop');
} else {
puter.print('Desktop write access denied');
}
});
</script>
</body>
</html>