Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JMichaelTX/f696bb95f6246f546505 to your computer and use it in GitHub Desktop.
Save JMichaelTX/f696bb95f6246f546505 to your computer and use it in GitHub Desktop.
[EN] Move a Tag to be a Child of a Parent Tag [JXA] - Evernote Mac, JavaScript for Automation
/*
⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶
[EN] How to Make Tag a Child Tag of a Parent Tag [JXA]
⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶
DATE: Fri, Jan 15, 2016
AUTHOR: JMichaelTX (in most forums)
Find any bugs/issues or have suggestions for improvement?
Post below, or contact me via PM or at blog.jmichaeltx.com/contact/
REF:
⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶⩶
*/
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var ENapp = Application("Evernote");
var tagNameStr
var tagParStr
var strMsg = "Enter the Tag You Want to Move Under a Parent Tag"
var strTitle = "Move Tag"
app.beep()
var oAns = app.displayDialog(strMsg,
{
withTitle: strTitle,
withIcon: "caution",
defaultAnswer: ""
})
tagNameStr = oAns.textReturned
strMsg = "Enter the PARENT Tag for Tag " + tagNameStr
app.beep()
var oAns = app.displayDialog(strMsg,
{
withTitle: strTitle,
withIcon: "caution",
defaultAnswer: ""
})
tagParStr = oAns.textReturned
var tagObj = ENapp.tags.byName(tagNameStr);
var tagParObj = ENapp.tags.byName(tagParStr);
if (tagObj.exists()) {
if (tagParObj.exists()) {
//--- SET THE PARENT TAG ---
tagObj.parent = tagParObj
console.log('Tag: ' + tagObj.name() + ' Parent: ' + tagObj.parent.name())
app.displayAlert ('SUCCESS! \nTag: ' + tagObj.name()
+ ' \n has been moved to a child tag of '
+ '\nParent Tag: ' + tagObj.parent.name()
);
} else {
app.displayAlert('Parent Tag: ' + tagParStr + ' does NOT EXIST')
} // END if (tagParObj.exists())
} else {
app.displayAlert('Tag: ' + tagNameStr + ' does NOT EXIST')
} // END if (tagObj.exists())
@JMichaelTX
Copy link
Author

JMichaelTX JXA Gists

Because there is so little JavaScript for Automation (JXA) code that is published, I plan to publish as much as I can that will hopefully be of help to others learning JXA.

Much of what I publish will be based on the work of others, and I always try to cite those references in the code header. If I have failed to properly credit your code, please post a comment, and I will correct my Gist.

Your JXA Code

If you have example code you'd like to share, please post a link to your code. After having searched and evaluated various options for posting/sharing code, i have concluded that Github Gists is the best.

Bugs/Issues & Suggestions

If you find any bugs or issues, or have suggestions for improvement, please feel free to post a comment.

For more info, see JavaScript for Automation (JXA) Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment