Skip to content

Commit

Permalink
add generate-script-steps script
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillinghalpern committed Oct 18, 2024
1 parent d72cae0 commit 7172b54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"deploy-to-fm": "npm run build && npm run upload",
"build": "parcel build index.html",
"upload": "node ./scripts/upload",
"generate-script-steps": "node ./scripts/generate-script-steps",
"clear-cache": "rm -rf .parcel-cache dist",
"reset-dev": "npm run clear-cache && npm run start",
"start-fm-dev": "node ./scripts/start-fm-dev",
Expand Down
28 changes: 28 additions & 0 deletions scripts/generate-script-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { exec, spawn } = require("child_process");

function pbcopy(data) {
const proc = spawn("pbcopy");
proc.stdin.write(data);
proc.stdin.end();
}

function convertClipboardToFM() {
exec(
"osascript -e 'set the clipboard to (do shell script \"pbpaste\" as «class XMSS»)'",
(error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
}
);
}

const xml = `<fmxmlsnippet type="FMObjectList"><Step enable="True" id="141" name="Set Variable"><Value><Calculation><![CDATA[JSONGetElement ( Get ( ScriptParameter ) ; "callbackName" )]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$callbackName</Name></Step><Step enable="True" id="141" name="Set Variable"><Value><Calculation><![CDATA[JSONGetElement ( Get ( ScriptParameter ) ; "promiseID" )]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$promiseID</Name></Step><Step enable="True" id="141" name="Set Variable"><Value><Calculation><![CDATA[JSONGetElement ( Get ( ScriptParameter ) ; "parameter" )]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$parameter</Name></Step><Step enable="True" id="89" name="# (comment)"></Step><Step enable="True" id="89" name="# (comment)"><Text>Your logic here</Text></Step><Step enable="True" id="89" name="# (comment)"></Step><Step enable="True" id="141" name="Set Variable"><Value><Calculation><![CDATA["wv"]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$webviewer</Name></Step><Step enable="True" id="175" name="Perform JavaScript in Web Viewer"><ObjectName><Calculation><![CDATA[$webviewer]]></Calculation></ObjectName><FunctionName><Calculation><![CDATA[$callbackName]]></Calculation></FunctionName><Parameters Count="1"><P><Calculation><![CDATA[$promiseID]]></Calculation></P></Parameters></Step></fmxmlsnippet>`;

pbcopy(xml);
console.log("\x1b[34mXML copied to clipboard.\x1b[0m");
convertClipboardToFM();
console.log(
"\x1b[32mConverted to script steps. Go paste it in your FM script!\x1b[0m"
);

0 comments on commit 7172b54

Please sign in to comment.