1"use strict";(globalThis.webpackChunktalon_wiki=globalThis.webpackChunktalon_wiki||[]).push([[5169],{4545(e,s,i){i.r(s),i.d(s,{assets:()=>l,contentTitle:()=>r,default:()=>d,frontMatter:()=>o,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"Customization/Talon Framework/scopes","title":"Scopes","description":"Scopes allow you to supply additional properties that can be matched in the header of .talon files or by the Context.matches string in Python. This could be used to make the window title from your current virtual machine window available to Talon for example. Another might be to tell Talon which mode your full-screen computer game is in. In practise they are not used very often.","source":"@site/docs/Customization/Talon Framework/scopes.md","sourceDirName":"Customization/Talon Framework","slug":"/Customization/Talon Framework/scopes","permalink":"/Customization/Talon Framework/scopes","draft":false,"unlisted":false,"editUrl":"https://github.com/TalonCommunity/Wiki/edit/main/docs/Customization/Talon Framework/scopes.md","tags":[],"version":"current","frontMatter":{},"sidebar":"CustomizationSidebar","previous":{"title":"Modes","permalink":"/Customization/Talon Framework/modes"},"next":{"title":"Settings","permalink":"/Customization/Talon Framework/settings"}}');var a=i(4848),t=i(8453);const o={},r="Scopes",l={},c=[];function h(e){const s={a:"a",code:"code",h1:"h1",header:"header",p:"p",pre:"pre",span:"span",...(0,t.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.header,{children:(0,a.jsx)(s.h1,{id:"scopes",children:"Scopes"})}),"\n",(0,a.jsxs)(s.p,{children:["Scopes allow you to supply additional properties that can be matched in the header of ",(0,a.jsx)(s.code,{children:".talon"})," files or by the ",(0,a.jsx)(s.code,{children:"Context.matches"})," string in Python. This could be used to make the window title from your current virtual machine window available to Talon for example. Another might be to tell Talon which mode your full-screen computer game is in. In practise they are not used very often."]}),"\n",(0,a.jsx)(s.p,{children:"You need to write custom Python code to keep your scope information up to date. The following example implements a scope that makes the current time available as a matcher property."}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.code,{children:"test.py"})}),"\n",(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.pre,{className:"shiki shiki-themes catppuccin-latte catppuccin-macchiato",style:{backgroundColor:"#eff1f5","--shiki-dark-bg":"#24273a",color:"#4c4f69","--shiki-dark":"#cad3f5"},tabIndex:"0",children:(0,a.jsxs)(s.code,{children:[(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#8839EF","--shiki-dark":"#C6A0F6"},children:"import"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" datetime"})]}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#8839EF","--shiki-dark":"#C6A0F6"},children:"from"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" talon "}),(0,a.jsx)(s.span,{style:{color:"#8839EF","--shiki-dark":"#C6A0F6"},children:"import"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" Module"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:","}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" cron"})]}),"\n",(0,a.jsx)(s.span,{className:"line"}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:"mod "}),(0,a.jsx)(s.span,{style:{color:"#179299","--shiki-dark":"#8BD5CA"},children:"="}),(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:" Module"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"()"})]}),"\n",(0,a.jsx)(s.span,{className:"line"}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#FE640B",fontStyle:"italic","--shiki-dark":"#F5A97F","--shiki-dark-font-style":"italic"},children:"@mod"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"."}),(0,a.jsx)(s.span,{style:{color:"#FE640B",fontStyle:"italic","--shiki-dark":"#F5A97F","--shiki-dark-font-style":"italic"},children:"scope"})]}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#8839EF","--shiki-dark":"#C6A0F6"},children:"def"}),(0,a.jsx)(s.span,{style:{color:"#1E66F5",fontStyle:"italic","--shiki-dark":"#8AADF4","--shiki-dark-font-style":"italic"},children:" my_scope_updater"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"}
1,children:"():"})]}),"\n",(0,a.jsx)(s.span,{className:"line",children:(0,a.jsx)(s.span,{style:{color:"#7C7F93",fontStyle:"italic","--shiki-dark":"#939AB7","--shiki-dark-font-style":"italic"},children:' # Sets the user.current_time scope to something like "04:12 PM"'})}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#8839EF","--shiki-dark":"#C6A0F6"},children:" return"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:" {"}),(0,a.jsx)(s.span,{style:{color:"#40A02B","--shiki-dark":"#A6DA95"},children:'"current_time"'}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:":"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" datetime"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"."}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:"datetime"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"."}),(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:"now"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"()."}),(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:"strftime"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"("}),(0,a.jsx)(s.span,{style:{color:"#40A02B","--shiki-dark":"#A6DA95"},children:'"%I:%M %p"'}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:")}"})]}),"\n",(0,a.jsx)(s.span,{className:"line"}),"\n",(0,a.jsx)(s.span,{className:"line",children:(0,a.jsx)(s.span,{style:{color:"#7C7F93",fontStyle:"italic","--shiki-dark":"#939AB7","--shiki-dark-font-style":"italic"},children:"# Re-run the above code every minute to update the scope. You can run"})}),"\n",(0,a.jsx)(s.span,{className:"line",children:(0,a.jsx)(s.span,{style:{color:"#7C7F93",fontStyle:"italic","--shiki-dark":"#939AB7","--shiki-dark-font-style":"italic"},children:"# <scope function>.update() from anywhere you like to trigger an update."})}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:"cron"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"."}),(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:"interval"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"("}),(0,a.jsx)(s.span,{style:{color:"#40A02B","--shiki-dark":"#A6DA95"},children:'"1m"'}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:","}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:" my_scope_updater"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:"."}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:"update"}),(0,a.jsx)(s.span,{style:{color:"#7C7F93","--shiki-dark":"#939AB7"},children:")"})]})]})})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.code,{children:"test.talon"})}),"\n",(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.pre,{className:"shiki shiki-themes catppuccin-latte catppuccin-macchiato",style:{backgroundColor:"#eff1f5","--shiki-dark-bg":"#24273a",color:"#4c4f69","--shiki-dark":"#cad3f5"},tabIndex:"0",children:(0,a.jsxs)(s.code,{children:[(0,a.jsx)(s.span,{className:"line",children:(0,a.jsx)(s.span,{style:{color:"#7C7F93",fontStyle:"italic","--shiki-dark":"#939AB7","--shiki-dark-font-style":"italic"},children:"# This matcher can either be a plain string or a regex"})}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:"user.current_time"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:": /AM$/"})]}),"\n",(0,a.jsx)(s.span,{className:"line",children:(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:"-"})}),"\n",(0,a.jsxs)(s.span,{className:"line",children:[(0,a.jsx)(s.span,{style:{color:"#1E66F5","--shiki-dark":"#8AADF4"},children:"is it morning"}),(0,a.jsx)(s.span,{style:{color:"#4C4F69","--shiki-dark":"#CAD3F5"},children:": "}),(0,a.jsx)(s.span,{style:{color:"#40A02B","--shiki-dark":"#A6DA95"},children:'"yes it is!"'})]})]})})}),"\n",(0,a.jsxs)(s.p,{children:[(0,a.jsx)(s.code,{children:"scopes"})," are 'global' in the sense that you can't override them for particular contexts in the same way as actions. Any file can simply overwrite a particular scope's value b
1y implementing some python code like the above."]}),"\n",(0,a.jsxs)(s.p,{children:["You may have noticed that scopes can emulate the behaviour of ",(0,a.jsx)(s.a,{href:"tags",children:"tags"}),", except you have to manage any context switches yourself. In practise tags are used far more often than scopes as they're both simpler to use, and are also self documenting. This leads to the recommendation that if you are able to use a tag for your use-case, then generally you would do that. If you need the string matching behaviour of scopes then you might consider those."]})]})}function d(e={}){const{wrapper:s}={...(0,t.R)(),...e.components};return s?(0,a.jsx)(s,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},8453(e,s,i){i.d(s,{R:()=>o,x:()=>r});var n=i(6540);const a={},t=n.createContext(a);function o(e){const s=n.useContext(t);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function r(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(t.Provider,{value:s},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.