Skip to content

Commit

Permalink
Merge pull request #2 from wrjlewis/alfred5-updates
Browse files Browse the repository at this point in the history
Alfred5 Updates (user config improvements)
  • Loading branch information
wrjlewis authored Nov 27, 2022
2 parents 3023ed9 + 93e95a1 commit a91000c
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 67 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ The workflow also provides the ability to quickly see your __recently viewed pag

![img](https://github.com/wrjlewis/notion-search-alfred-workflow/blob/31d36ee9e75c343045f2a1f313b03373669a7730/notion-demo.gif)

## Workflow Variables
## User Configuration

- `cookie`: Needed for your Notion token.
- `notionSpaceId`: Your organisation identifier.
- `isNavigableOnly`: Defaults to False. This settings allows you to search objects within a page, ie notion objects that cannot be found through the left hand side navigation pane. Setting to True only returns results that can be found through the left hand side navigation pane, but removes subtitles from Alred search results.
- `useDesktopClient`: Defaults to False. Determines whether to open Notion links in the desktop client rather than the web app.
- `enableIcons`: Defaults to True. This toggles support for Notion icons to be shown natively in Alfred search results, for a better design/UX experience. Custom Notion icons are downloaded on demand.
- `iconCacheDays`: Defaults to the recommended value of 365 days for the best performance. Defines the number of days to cache custom icons. Min 0, max 365.
- `showRecentlyViewedPages`: Defaults to True. This toggle determines if recently viewed pages should be shown when there is no query provided by the user and the user id is present in the supplied cookie (user id is needed for the api call to show recently viewed pages).
- `Cookie`: Needed for your Notion token.
- `Space ID`: Your organisation identifier.
- `Navigable Only`: Defaults to False. Setting to false allows you to search objects within a page, ie notion objects that cannot be found through the left hand side navigation pane.
- `Use Desktop Client`: Defaults to False. Determines whether to open Notion links in the desktop client rather than the web app.
- `Enable Icons`: Defaults to True. This toggles support for Notion icons to be shown natively in Alfred search results, for a better design/UX experience. Custom Notion icons are downloaded on demand and cached.
- `Show Recently Viewed`: Defaults to True. This toggle determines if recently viewed pages should be shown when there is no query provided by the user and the user id is present in the supplied cookie (user id is needed for the api call to show recently viewed pages).
- `Icon Cache Days`: Defaults to the recommended value of 365 days for the best performance. Defines the number of days to cache icons and images. Min 0, max 365.

## Install Steps

Expand All @@ -31,7 +31,7 @@ Install cairosvg which will allow svg icons to be shown in Alfred search results

I recommend using chrome to retrieve these values. If you can only use safari you can copy the 'token_v2' value by following the equivalent steps above and populating the cookie env variable in Alfred so it looks like this `token_v2=XXXXXXXXXXXX`.

Visit the Notion webapp and use your browser developer tools to see the network requests being made when you type in anything to the quick find search bar.
Visit the Notion webapp and use your browser developer tools to see the network requests being made when you type in anything to the quick find search bar.

Here you'll see a request called `search`, check the request headers to copy the `cookie` value and check the request payload to copy your `notionSpaceId`.

Expand Down
174 changes: 146 additions & 28 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<integer>0</integer>
<key>script</key>
<string># THESE VARIABLES MUST BE SET. SEE THE ONEUPDATER README FOR AN EXPLANATION OF EACH.
readonly remote_info_plist='https://raw.githubusercontent.com/wrjlewis/notion-search-alfred-workflow/master/info.plist'
readonly workflow_url='wrjlewis/notion-search-alfred-workflow'
readonly remote_info_plist='https://raw.githubusercontent.com/wrjlewis/notion-search-alfred5-workflow/master/info.plist'
readonly workflow_url='wrjlewis/notion-search-alfred5-workflow'
readonly download_type='github_release'
readonly frequency_check='1'
Expand Down Expand Up @@ -216,8 +216,8 @@ An Alfred workflow to search Notion.so with instant results
Simply type your keyword into Alfred (default: ns) to see instant search results from Notion that mimic the Quick Find function in the Notion webapp. Selecting a search result takes you to that page in Notion in your default web browser.
Documentation, instructions on workflow variables in the readme here:
https://github.com/wrjlewis/notion-search-alfred-workflow/
Documentation, install and instructions here:
https://github.com/wrjlewis/notion-search-alfred5-workflow/
Forum topic:
https://www.alfredforum.com/topic/14451-notionso-instant-search-workflow/
Expand Down Expand Up @@ -252,32 +252,150 @@ Thanks!</string>
</dict>
</dict>
<key>userconfigurationconfig</key>
<array/>
<key>variables</key>
<dict>
<key>cookie</key>
<string></string>
<key>enableIcons</key>
<string>True</string>
<key>iconCacheDays</key>
<string>365</string>
<key>isNavigableOnly</key>
<string>False</string>
<key>notionSpaceId</key>
<string></string>
<key>showRecentlyViewedPages</key>
<string>True</string>
<key>useDesktopClient</key>
<string>False</string>
</dict>
<key>variablesdontexport</key>
<array>
<string>cookie</string>
<string>notionSpaceId</string>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string></string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>Needed for your Notion token.</string>
<key>label</key>
<string>Cookie</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>cookie</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string></string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>Your organisation identifier.</string>
<key>label</key>
<string>Space ID</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>notionSpaceId</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<false/>
<key>required</key>
<false/>
<key>text</key>
<string>If unchecked, allows searching objects within a page</string>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Navigable Only</string>
<key>type</key>
<string>checkbox</string>
<key>variable</key>
<string>isNavigableOnly</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<false/>
<key>required</key>
<false/>
<key>text</key>
<string>If checked, open links in the desktop app</string>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Use Desktop Client</string>
<key>type</key>
<string>checkbox</string>
<key>variable</key>
<string>useDesktopClient</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<true/>
<key>required</key>
<false/>
<key>text</key>
<string>Show Notion icons natively in search results</string>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Enable Icons</string>
<key>type</key>
<string>checkbox</string>
<key>variable</key>
<string>enableIcons</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<true/>
<key>required</key>
<false/>
<key>text</key>
<string>Show recently viewed pages when no query provided</string>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Show Recently Viewed</string>
<key>type</key>
<string>checkbox</string>
<key>variable</key>
<string>showRecentlyViewedPages</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>365</string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Icon Cache Days</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>iconCacheDays</string>
</dict>
</array>
<key>version</key>
<string>0.5-alfred4</string>
<string>0.5-alfred5</string>
<key>webaddress</key>
<string>https://github.com/wrjlewis/notion-search-alfred-workflow/</string>
<string>https://github.com/wrjlewis/notion-search-alfred5-workflow/</string>
</dict>
</plist>
</plist>
36 changes: 6 additions & 30 deletions notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,13 @@
for key, morsel in bakedCookie.items():
bakedCookies[key] = morsel.value

# get useDesktopClient env variable and convert to boolean for use later, default to false
useDesktopClient = os.environ['useDesktopClient']
if (useDesktopClient == 'true') | (useDesktopClient == 'True') | (useDesktopClient == 'TRUE'):
useDesktopClient = True
else:
useDesktopClient = False

# get isNavigableOnly env variable and convert to boolean for use later, default to true
isNavigableOnly = os.environ['isNavigableOnly']
if (isNavigableOnly == 'false') | (isNavigableOnly == 'False') | (isNavigableOnly == 'FALSE'):
isNavigableOnly = False
else:
isNavigableOnly = True

# get enableIcons env variable and convert to boolean for use later, default to true
enableIcons = os.environ['enableIcons']
if (enableIcons == 'false') | (enableIcons == 'False') | (enableIcons == 'FALSE'):
enableIcons = False
else:
enableIcons = True

# get the number of days to cache custom icons. Min 0, max 365. Defaults to the maximum of 365 days
# get togglable env variables and convert to boolean for later use
useDesktopClient = os.environ['useDesktopClient'] == "1"
isNavigableOnly = os.environ['isNavigableOnly'] == "1"
enableIcons = os.environ['enableIcons'] == "1"
showRecentlyViewedPages = os.environ['showRecentlyViewedPages'] == "1"
iconCacheDays = sorted([0, int(os.environ['iconCacheDays']), 365])[1]

# get showRecentlyViewedPages env variable and convert to boolean for use later, default to true
showRecentlyViewedPages = os.environ['showRecentlyViewedPages']
if (showRecentlyViewedPages == 'false') | (showRecentlyViewedPages == 'False') | (showRecentlyViewedPages == 'FALSE'):
showRecentlyViewedPages = False
else:
showRecentlyViewedPages = True

exception = ""

def buildnotionsearchquerydata():
Expand Down Expand Up @@ -334,7 +310,7 @@ def createSubtitleChain(recordMap, id):
searchResultObject.icon = None
searchResultObject.title = searchResults.recordMap.get('block').get(searchResultObject.id).get(
'value').get('format').get('page_icon') + " " + searchResultObject.title

searchResultObject.link = getnotionurl() + searchResultObject.id.replace("-", "")
searchResultList.append(searchResultObject)
except Exception as e:
Expand Down

0 comments on commit a91000c

Please sign in to comment.