Hi, guys, I am a newbie to Alfred. I want to use Alfred Snippets to do some text expanding task.
Like writing the markdown liquid headers in my blogs:
---
layout:post
title: 2-debugger_demo.md
date: 2021-11-06 15:34:07 +08:00
tags: []
toc: true
---
I use Typinator before, I can customize my snippet as following:
---
layout:post
title: {Scripts/FrontWindowTitle.applescript}
date: {YYYY}-{MM}-{DD} {h024}:{m}:{s} {zn}
tags: []
toc: true
---
In above snippet, {YYYY}-{MM}-{DD} {h024}:{m}:{s} {zn} works like {date:yyyy-MM-dd HH:mm:ss Z} in Alfred snippet.
What I cares is the property `title: {Scripts/FrontWindowTitle.applescript}`. Here this applescript just returns the frontmost window's title. At most occassions, this title is the document's name. That's what I want.
The script file is as following, which is very easy:
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
set windowTitle to the name of the front window
end tell
return windowTitle
Now I want to use Alfred Snippet & Snippet Trigger to replace Typinator, so I:
- add a snippet in Alfred :
---
layout:post
title: {cursor}
date: {date:yyyy-MM-dd HH:mm:ss Z}
tags: []
toc: true
---
- and I add a workflow including a Snippet Trigger:
Here, step 2 applescript update {query} to the window title, and copy to clipboard.
I can type `\\title` to get the title of window correctly.
But when I type `!post` which triggers the snippet, it generate:
---
layout:post
title: {snippet:\\title}
date: 2021-11-06 15:48:08 +0800
tags: []
toc: true
---
Apparently, it didn't call the Snippet Trigger.
I don't know how to solve this problem,
Please help me. Thanks!