Jump to content

Snippets to work only with certain Lauguage input


Korean Guy

Recommended Posts

I love the snippets feature and uses like 100 times a day!

One thing I wish Alfred could is, I could set up a certain group of snippets to be working on certain language input mode only

for example I use ;br to make it best regards, I never type ;br on English, but I use it when I type different language.

So it would be nice to make it disable this snippet to work when I'm using different language.

Many thanks!!!!

Link to comment
Share on other sites

Could you provide an example that Westerners would understand, @Korean Guy?

 

I don't really see the point myself. I deliberately leverage the key re-mapping when I switch input language to "localise" my snippets.

 

For example, I have the English date (dd/MM/yyyy) mapped to zzdd and the German date (dd.MM.yyyy) mapped to yydd.


That way, hitting the same physical keys will give me the English date when I'm using English input and the German date when I'm using German input (the Z and Y keys are swapped on English/German layouts).

 

Importantly, I can still access the other snippet under a different keyword when I'm writing something that contains both languages (which I do fairly often).

Link to comment
Share on other sites

1 hour ago, deanishe said:

Could you provide an example that Westerners would understand, @Korean Guy?

 

I don't really see the point myself. I deliberately leverage the key re-mapping when I switch input language to "localise" my snippets.

 

For example, I have the English date (dd/MM/yyyy) mapped to zzdd and the German date (dd.MM.yyyy) mapped to yydd.


That way, hitting the same physical keys will give me the English date when I'm using English input and the German date when I'm using German input (the Z and Y keys are swapped on English/German layouts).

 

Importantly, I can still access the other snippet under a different keyword when I'm writing something that contains both languages (which I do fairly often).

Thanks for your feedback @deanishe

Yes if it was like Simple zzdd or yydd only then maybe less likely you have overlapping snippets.

But I use English Japanese Chinese Korean and while I register lots of lots of snippets of 4 languages, snippets would trigger accidentally while I am using different language. 

For exalmple my snippets are something like ili ijh jun etc, and these would never triggered accidentally while I type Asian languages but it would when I type English. 

It’s like you have to type zzdd or yydd on other strange languages. 

I know I can put .. or ;; before snippets but I use them so often so I try to make it short as much as possible.  :)

Link to comment
Share on other sites

30 minutes ago, Korean Guy said:

I use English Japanese Chinese Korean

 

Right. Four languages is quite a lot.

 

26 minutes ago, Korean Guy said:

It’s like you have to type zzdd or yydd on other strange languages.

 

Sure. When it comes to system-wide snippet expansion, it's generally considered best practice to use snippet triggers that you would never, ever normally type.

Link to comment
Share on other sites

Another option that I personally use (don't have many text triggered expansions) is searching through expansions you need. I have bad memory for things that I don't use often so text expansions outside of ones like (:s or :d to expand my current Safari URL or embed URL into a markdown image) are going to be forgotten and not used. So I use Typinator's smart search which (in my experience) after few typed characters always knows the trigger I want to expand. This way I don't have to remember the triggers as I get visual feedback for what the triggers I have by typing few characters from the expanded result.

 

Looks like this:

 

895237739_2018-11-10at17_22.png.b2c605716df30ebca9c755114a59657b.png

Link to comment
Share on other sites

Thanks everyone for your insight into why you're suggesting this.

 

I'll be upfront and say it's highly unlikely we'd implement something like this, as there's very little benefit. As @deanishe suggested, best practice is to use snippets that will never be triggered accidentally - regardless of your current keyboard language.

 

I frequently switch between French and English, and have snippet collections for the various purposes. However, I always make sure my snippets are obscure enough to never be triggered accidentally. 

 

If you're not familiar with them, do take a look at the affixes; Setting a collection-wide prefix is a convenient way of creating new snippets without having to make sure you're manually being consistent about your prefixes:

https://www.alfredapp.com/help/features/snippets/collections/

 

e.g. A few of my English collections use :: as prefix, while my French collection uses // as prefix.

 

@nikivi You can use the Snippets viewer to do pretty much exactly what you've described. Pop up the Clipboard using its hotkey (or set a Snippet Viewer hotkey) and either navigate into a Snippet Collection, or simply start typing the title or keyword of a snippet. You'll see the full snippet on the right, and the keyword at the bottom to remind you of precisely what the snippet keyword is for next time. :)

 

Screen Shot 2018-11-12 at 08.56.31.png

 

Cheers,
Vero

 

 

Link to comment
Share on other sites

I have noticed that there's a Snippet Trigger, which I assume allows one to create a keyword shortcut that acts as a snippet, expanding to whatever result of the ensuing workflow yields.  Is that anywhere close to how it works ?


If so, an off-the-top-of-my-head idea and without much firsthand experience using Alfred snippets (I use Typinator), makes it seem to me that it might be possible to create snippets that share a common abbreviation/keyword, but—through a multi-pronged workflow that incorporates a tiny bit of scripting—could expand to produce something that depends entirely upon the currently selected keyboard input source.

 

I'm not the best person to play around with this, as I'm monolingual.  However, I have put together a few lines of key Javascript for Automation (JXA) code that would prove useful if anyone else wanted to see what they can do to make snippets more flexible or less likely to clash for multilingual persons:

 

 

ObjC.import('AppKit');

 

inputContext = $.NSTextInputContext.currentInputContext;

 

inputSources = ObjC.deepUnwrap(inputContext.keyboardInputSources);

inputSource  = ObjC.unwrap(inputContext.selectedKeyboardInputSource);

         //--> "com.apple.keylayout.British"

 

localisedName = ObjC.unwrap(

                   $.NSTextInputContext

                    .localizedNameForInputSource(inputSource)

); //--> "British"

 

 

I've printed example values for the last two variables, which are actual values returned on my system.  The other value of possible interest is the variable inputSources, which produces a list of available input sources, mirroring what appears listed in the input menu if you have it accessible from the menu bar.

 

Edited by CJK
Link to comment
Share on other sites

13 hours ago, deanishe said:

 

Definitely not a programmer (or one of those evil ones that never comments anything) ;)

 

 

Haha, keep in mind, // has to be followed directly by no space and the precise snippet, so // itself will never trigger anything. (And to be fair, my French collection only contains about 10 snippets, otherwise I might've picked something different). 

 

My daily-use Alfred support snippets collection doesn't need affixees, and the snippet keywords themselves are suitably obscure, yet extremely easy to type because they get constant use! :D 

 

Cheers,
Vero

Link to comment
Share on other sites

20 hours ago, CJK said:

I have noticed that there's a Snippet Trigger, which I assume allows one to create a keyword shortcut that acts as a snippet, expanding to whatever result of the ensuing workflow yields.  Is that anywhere close to how it works ?

 

Mostly. Snippet Triggers just launch workflows (after deleting the keyword). If you actually want to insert some text, which you probably do, you have to do that manually with the Copy & Paste Output.

 

Their strength is launching List/Script Filters, so you can, say, just use one snippet to bring up a list of all the emojis and then choose the one you want instead of trying to remember a hundred different keywords.

 

Using them to replicate regular snippets would be pretty cumbersome and not a whole lot of fun.

 

Handy snippet, though. Is the “inputSources” line necessary? You don’t seem to use the variable again.

Link to comment
Share on other sites

1 hour ago, deanishe said:

Is the “inputSources” line necessary? You don’t seem to use the variable again

 

Nope.  The script isn't presented as achieving any particular objective; it doesn't really do anything in its current state.  It's just a triplet of related code snippets that demonstrate how to retrieve their respective bits of information, and I just failed to properly segregate or itemise them.

 

1 hour ago, deanishe said:

Their strength is launching List/Script Filters, so you can, say, just use one snippet to bring up a list of all the emojis and then choose the one you want instead of trying to remember a hundred different keywords.

 

So in this example, what's the snippet trigger doing that a keyword list filter isn't ?  If a list filter contained all the emojis, then they would get shown by typing a single keyword, no ?

Link to comment
Share on other sites

2 hours ago, CJK said:

The script isn't presented as achieving any particular objective; it doesn't really do anything in its current state.

 

I understand perfectly what the code snippet does. I was just mildly confused by that line and wondered if it was perhaps a workaround for some strange bug.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...