Skip to content

Commit

Permalink
More robust new note creation, show enclosing folder before note
Browse files Browse the repository at this point in the history
  • Loading branch information
sballin committed Mar 1, 2024
1 parent a499aca commit 7397d78
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,19 @@ fi</string>
<key>config</key>
<dict>
<key>applescript</key>
<string>-- This script takes "URLs" of format "identifier,itemID,accountID,itemFolderID,userQuery" or just "userQuery"-- accountID can be the string "null", if so the default account is used-- Some commands need to run twice, otherwise they fail when toolbar search is activeon alfred_script(q) try if q contains "/ICNote/p" or q contains "/ICFolder/p" then set AppleScript's text item delimiters to "," set identifier to text item 1 of q set itemID to text item 2 of q set accountID to text item 3 of q set itemFolderID to text item 4 of q set AppleScript's text item delimiters to "" tell application "Notes" if itemID contains "/ICNote/p" then -- Show user-requested note open location "notes://showNote?identifier=" &amp; identifier open location "notes://showNote?identifier=" &amp; identifier -- Compatibility with macOS &lt; 11 which does not support notes:// set OSVersion to system version of (system info) set mainVersion to text 1 thru ((offset of "." in OSVersion) - 1) of OSVersion as number if mainVersion &lt; 11 then if accountID is "null" then show note id itemID in default account show note id itemID in default account else show note id itemID in account id accountID show note id itemID in account id accountID end if end if
<string>-- This script takes "URLs" of format "identifier,itemID,accountID,itemFolderID,userQuery" or just "userQuery"-- accountID can be the string "null", if so the default account is used-- Some commands need to run twice, otherwise they fail when toolbar search is activeon alfred_script(q) try if q contains "/ICNote/p" or q contains "/ICFolder/p" then set AppleScript's text item delimiters to "," set identifier to text item 1 of q set itemID to text item 2 of q set accountID to text item 3 of q set itemFolderID to text item 4 of q set AppleScript's text item delimiters to "" tell application "Notes" if itemID contains "/ICNote/p" then
if itemFolderID is not "null" then if accountID is "null" then show folder id itemFolderID in default account else show folder id itemFolderID in account id accountID end if
end if else if itemID contains "/ICFolder/p" then -- Show user-requested folder if accountID is "null" then show folder id itemID in default account show folder id itemID in default account else show folder id itemID in account id accountID show folder id itemID in account id accountID end if end if end tell else tell application "Notes" -- Create new note from user query tell default account to make new note at default folder with properties {body:"&lt;div&gt;&lt;h1&gt;" &amp; q &amp; "&lt;/h1&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;"} show first note in default account show first note in default account end tell
-- Position cursor in body of new note
try
tell application "System Events" tell process "Notes"
set focused of scroll area 3 of splitter group 1 of window 1 to true
key code {125, 125} -- down, down
end tell
end if -- Show user-requested note open location "notes://showNote?identifier=" &amp; identifier open location "notes://showNote?identifier=" &amp; identifier -- Compatibility with macOS &lt; 11 which does not support notes:// set OSVersion to system version of (system info) set mainVersion to text 1 thru ((offset of "." in OSVersion) - 1) of OSVersion as number if mainVersion &lt; 11 then if accountID is "null" then show note id itemID in default account show note id itemID in default account else show note id itemID in account id accountID show note id itemID in account id accountID end if end if else if itemID contains "/ICFolder/p" then -- Show user-requested folder if accountID is "null" then show folder id itemID in default account show folder id itemID in default account else show folder id itemID in account id accountID show folder id itemID in account id accountID end if end if end tell else tell application "Notes"
show default folder in default account
show default folder in default account
delay 0.5 -- to avoid any still-pressed keys interfering
end tell
tell application "System Events" tell process "Notes"
keystroke "n" using command down
keystroke q
key code {36, 36} -- enter, enter
end tell
end try end if on error errorMessage number errorNumber display alert "Show Note Error" message ((errorNumber as string) &amp; ": " &amp; errorMessage &amp; "
end tell end if on error errorMessage number errorNumber display alert "Show Note Error" message ((errorNumber as string) &amp; ": " &amp; errorMessage &amp; "
Input: " &amp; q) as critical end tryend alfred_script</string>
<key>cachescript</key>
Expand Down Expand Up @@ -992,25 +994,22 @@ end alfred_script</string>
on alfred_script(q)
try
tell application "Notes"
-- Create new note from user query
tell default account to make new note at default folder with properties {body:"&lt;div&gt;&lt;h1&gt;" &amp; q &amp; "&lt;/h1&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;"}
show first note in default account
show first note in default account
show default folder in default account
show default folder in default account
delay 0.5 -- to avoid any still-pressed keys interfering
end tell
-- Position cursor in body of new note
try
tell application "System Events" tell process "Notes"
set focused of scroll area 3 of splitter group 1 of window 1 to true
key code {125, 125} -- down, down
end tell
tell application "System Events" tell process "Notes"
keystroke "n" using command down
keystroke q
key code {36, 36} -- enter, enter
end tell
end try
end tell
on error errorMessage number errorNumber
display alert "Create Note Error" message (errorNumber as string &amp; ": " &amp; errorMessage &amp; "\n\nInput: " &amp; q) as critical
end try
end alfred_script</string>
<key>cachescript</key>
<true/>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.action.applescript</string>
Expand Down Expand Up @@ -1169,8 +1168,8 @@ fi</string>
</array>
<key>readme</key>
<string>## New in this version
- Position cursor in body of note after creating a new note
- Remove note glyph from links because it doesn't get rendered on iOS
- More robust new note creation
- Faster order of operations when showing a note in a folder
## Setup instructions and help
https://github.com/sballin/alfred-search-notes-app
Expand Down Expand Up @@ -1352,7 +1351,7 @@ or create note</string>
<string>1</string>
</dict>
<key>version</key>
<string>3.6.1</string>
<string>3.6.2</string>
<key>webaddress</key>
<string>https://github.com/sballin/alfred-search-notes-app</string>
</dict>
Expand Down

0 comments on commit 7397d78

Please sign in to comment.