This is not the same as shell.openExternal()
and you don’t have to use h
.
You have to create a hyperlink in your plugin’s UI and then when the user clicks on it it will open your folder.
So something like this:
/**
* Shorthand for creating Elements.
* @param {*} tag The tag name of the element.
* @param {*} [props] Optional props.
* @param {*} children Child elements or strings
*/
function h(tag, props, ...children) {
let element = document.createElement(tag);
if (props) {
if (props.nodeType || typeof props !== "object") {
children.unshift(props);
}
else {
for (let name in props) {
let value = props[name];
if (name == "style") {
Object.assign(element.style, value);
}
else {
element.setAttribute(name, value);
element[name] = value;
}
}
}
}
for (let child of children) {
element.appendChild(typeof child === "object" ? child : document.createTextNode(child));
}
return element;
}
function onsubmit() {
// dialog is automatically closed after submit unless you call e.preventDefault()
}
let labelWidth = 75;
let hyperlinkLabel = null;
let dialog =
h("dialog",
h("form", { method:"dialog", style: { width: 380 }, onsubmit },
h("h1", "Export Complete"),
h("label", { class: "row", marginTop:10 },
h("span", { style: { width: labelWidth, flex: "1" } }, "Export completed successfully!")
),
h("footer",
h("label", { class: "row", paddingTop:0, style: {border:"0px solid #888888", alignItems:"center"} },
hyperlinkLabel = h("a", { href:"",
style: {
textAlign: "center", marginTop:"0", position:"relative", top:"0", height:23, paddingTop:"4.5",
flex: "1" , backgroundColor:"#2D96F0", border:"0px solid #888888", verticalAlign:"middle",
paddingLeft:"16", paddingRight:"16", marginRight:"0", borderRadius: "12",
fontSize:"11px", fontWeight:"700", color:"#FFFFFF"
}
}, "Reveal in Finder")
),
h("button", { uxpVariant: "cta", type: "submit", onclick(e){ onsubmit(); dialog.close(); e.preventDefault; } }, "Close")
)
)
)
async function openAlert() {
const fileSystem = require("uxp").storage.localFileSystem;
document.body.appendChild(dialog);
dialog.showModal();
const pluginFolder = await fileSystem.getPluginFolder();
var path = "file://" + pluginFolder.nativePath;
hyperlinkLabel.href = path;
hyperlinkLabel.title = path;
}
module.exports = {
commands: {
menuCommand: openAlert
}
};
Manifest:
{
"id": "UI_OPEN_IN_FINDER",
"name": "(UI) Open in Finder",
"version": "1.0.0",
"host": {
"app": "XD",
"minVersion": "13.0.0"
},
"uiEntryPoints": [
{
"type": "menu",
"label": "Open in Finder",
"commandId": "menuCommand"
}
]
}
OpenInFinder.xdx (2.7 KB)