Created
February 13, 2016 02:56
-
-
Save JMichaelTX/e474691abb588aa84b95 to your computer and use it in GitHub Desktop.
Evernote Mac Set Note Creation Date from Selection using AppleScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
================================================================= | |
SCRIPT NAME: Set EN CreationDate from Selection | |
DATE: Thu, Jan 7, 2016 VER: 1.2 | |
PURPOSE: | |
• Set the EN Note Creation Date using text date which is selected | |
• Expects the text date format to be in the form based on current Sys Pref settings | |
• For USA: "Mon d, yyyy" or "m/d/yyyy" | |
• Example: Jan 7, 2015 | |
• OR to be in international date format, like "YYYY-MM-DD", where the dashes could be any character | |
• I wrote this to automate the setting of Creation Date for the many web pages I clip, which most | |
of the time were published on a prior date. | |
AUTHOR: JMichael (member of Discussion.Evernote.com forum) | |
Please PM me with any bugs/issues/questions | |
INSTALLATION: | |
• Copy to your personal Scripts folder: /Users/<YourName>/Library/Scripts/ | |
(create the Scripts folder if it does not exist) | |
HOW TO USE | |
• Select a Note in Evernote | |
• Select the text date in the Note you want to use for the Note Creation date | |
• Click on the Apple Scripts menu in the upper right area of your menu | |
• You can also use FastScripts (http://www.red-sweater.com/fastscripts/) | |
to setup a KB shortcut. | |
• Click on the name of this script: "Set EN CreationDate from Selection" | |
• The script will use this selected date to set the Note Creation Date | |
• A completion dialog window will be briefly show when completed | |
METHOD: | |
• Using the Clipboard | |
• There is no specific AppleScript function to copy text from an app to the Clipboard | |
• So, we have to rely on the "System Events" app to simulate a CMD-C | |
• Once you have the text date on the CB, you have go "tell" an app like EN to | |
set an AS variable to the CB. | |
• Handling dates and strings can be a challenge in AppleScript | |
• Couldn't find a general purpose text-to-date function that would handle all/most formats | |
• So, the code below relies on the text date format being consistent with the date settings | |
in the Mac Sys Prefs. | |
• See the MacScripter ref below | |
• Here are a few examples that will convert properly in the USA: | |
date "12/25/04" | |
date "12-25-04" | |
date "12 25 04" | |
date "dec 25 04" | |
date "25 DEC 2004" -- with or without commas | |
date "Dec 25, 2004" | |
-- All compile to: date "Saturday, December 25, 2004 12:00:00 AM" | |
• As of Ver 1.2, the international date format is accepted: | |
"YYYY-MM-DD", where the dashes could be any character | |
"2016-01-07", "2016/01/07", "2016.01.06" | |
REF: | |
1. AppleScript: Handling Date & Time -- MacScripter, Jul 23, 2007 | |
http://macscripter.net/viewtopic.php?id=24737 | |
2. FastScripts -- http://www.red-sweater.com/fastscripts/ | |
3. Get selected text from any application | |
http://macscripter.net/viewtopic.php?id=33575 | |
================================================================= | |
*) | |
property lsVer : "1.2" | |
property strCreationDate : "Jan 7, 2016" | |
set lsProcessTitle to "Evernote Set Creation Date " & lsVer | |
(* | |
================================== | |
COPY SELECTED TEXT TO CLIPBOARD | |
• Evernote MUST be the active application | |
• User MUST have selected TEXT in the Note | |
--================================== | |
*) | |
activate application "Evernote" | |
tell application "System Events" | |
keystroke "c" using command down -- Simulate CMD-C | |
end tell | |
-- MUST BE IN EVERNOTE TO COPY FROM CLIPBOARD --- | |
tell application "Evernote" | |
set strCreationDate to (the clipboard as text) | |
end tell | |
--display dialog strCreationDate | |
--========================================== | |
-- CONVERT TO DATE OBJECT | |
--========================================== | |
-- MUST NOT BE IN ANY APP WHEN USING THE date FUNCTION -- | |
try -- Try Standard U.S. date format -- | |
set dCreationDate to date (strCreationDate) | |
on error --- Try International Date format (YYYY-MM-DD) | |
set dCreationDate to convertIntlDate(strCreationDate) | |
end try | |
--display dialog "Date Object: " & dCreationDate | |
--========================================== | |
-- SET EN COMPLETION DATE | |
--========================================== | |
tell application "Evernote" | |
set _sel to selection -- Gets the Note(s) Selected in Evernote | |
if _sel ≠ {} then | |
set aNote to first item of _sel -- Get ONLY the 1st Note | |
set creation date of aNote to dCreationDate | |
else | |
display dialog "*** NOTE NOT SELECTED ***" | |
end if | |
end tell | |
beep | |
display notification ("Note Created Date set to: " & dCreationDate) with title lsProcessTitle | |
--======================= END OF MAIN SCRIPT ================ | |
to convertIntlDate(textDate) | |
--- textDate MUST be in the format of YYYY<delim>MM<delim>DD | |
--- where <delim> can be any character | |
--- like 2016-01-05 | |
set resultDate to the current date | |
set the year of resultDate to (text 1 thru 4 of textDate) | |
set the month of resultDate to (text 6 thru 7 of textDate) | |
set the day of resultDate to (text 9 thru 10 of textDate) | |
set the time of resultDate to 0 | |
if (length of textDate) > 10 then | |
set the hours of resultDate to (text 12 thru 13 of textDate) | |
set the minutes of resultDate to (text 15 thru 16 of textDate) | |
if (length of textDate) > 16 then | |
set the seconds of resultDate to (text 18 thru 19 of textDate) | |
end if | |
end if | |
return resultDate | |
end convertIntlDate | |
(* | |
===== END OF: Set EN CreationDate from Selection ===== | |
*) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are new to installing and/or using AppleScripts, or would like detailed instructions, see:
How to Install AppleScripts or JXA Scripts