Arguments not passed from Share Sheet

Hi,

Most probably I am missing something here. When I run the script below from Share Sheet (directly from Files.app, not via Scriptable.app) then I get an empty object in the args.js file

let fm = FileManager.local()
let fo = fm.documentsDirectory()
let fi = "args.js"
let aa = JSON.stringify(args)
fm.writeString(fo+"/"+fi, aa)

For this script I have selected all input types in “Share Sheet Inputs” inside Scriptable (Text, Images, URLs, File URLs) so it is available for most files in the Files.app, via Share > Run Script. But it seems that I never get any arguments passed to my script and the args.js always shows an empty object. I was expecting to have something passed into the global args object depending on the type of the input file.

Thanks,
Patryk

Try out this example and see if you have anything on your clipboard when you run it.

let al = new Alert();
al.message = args.urls.length.toString() + " URLs copied and ready to paste";
await al.present();
Pasteboard.copyString(args.urls.join("\n"))
return args.urls;

Brilliant - thank you! It seems my problem was with the JSON.stringify() function not parsing the args object correctly. Strangely, JSON.stringify(args.urls) shows everything as expected, but not JSON.stringify(args)