snipt

Ctrl+h for KB shortcuts

Python

Replace with Regex Groups

import re
re.sub("(?P<domain>https://.*twitter\\.com/)(?P<user>.+)/(?P<status>statuses)/(?P<id>.+)", "tweetbot://\g<user>/status/\g<id>", input-string)
https://snipt.net/embed/1d96ce43197c1358245b4f734c94bac8/
/raw/1d96ce43197c1358245b4f734c94bac8/
1d96ce43197c1358245b4f734c94bac8
python
Python
2
2019-06-07T17:54:28
True
False
False
Oct 26, 2012 at 09:29 AM
/api/public/snipt/49092/
replace-with-regex-groups
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">import</span> <span class="nn">re</span> </span><span id="L-2"><a name="L-2"></a><span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">&quot;(?P&lt;domain&gt;https://.*twitter</span><span class="se">\\</span><span class="s2">.com/)(?P&lt;user&gt;.+)/(?P&lt;status&gt;statuses)/(?P&lt;id&gt;.+)&quot;</span><span class="p">,</span> <span class="s2">&quot;tweetbot://\g&lt;user&gt;/status/\g&lt;id&gt;&quot;</span><span class="p">,</span> <span class="nb">input</span><span class="o">-</span><span class="n">string</span><span class="p">)</span> </span></pre></div> </td></tr></table>

Python

Regex Groups

(?P<domain>https://.*twitter\\.com/)(?P<user>.+)/(?P<status>statuses)/(?P<id>.+)
https://snipt.net/embed/8cf32404e81ec2ace43f024c2c81ed20/
/raw/8cf32404e81ec2ace43f024c2c81ed20/
8cf32404e81ec2ace43f024c2c81ed20
python
Python
1
2019-06-15T18:04:53
True
False
False
/api/public/snipt/49091/
regex-groups
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="err">?</span><span class="n">P</span><span class="o">&lt;</span><span class="n">domain</span><span class="o">&gt;</span><span class="n">https</span><span class="p">:</span><span class="o">//.*</span><span class="n">twitter</span>\\<span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="p">)(</span><span class="err">?</span><span class="n">P</span><span class="o">&lt;</span><span class="n">user</span><span class="o">&gt;.+</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="err">?</span><span class="n">P</span><span class="o">&lt;</span><span class="n">status</span><span class="o">&gt;</span><span class="n">statuses</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="err">?</span><span class="n">P</span><span class="o">&lt;</span><span class="nb">id</span><span class="o">&gt;.+</span><span class="p">)</span> </span></pre></div> </td></tr></table>

AppleScript

Applescript for modifying selected OmniFocus task

tell application "OmniFocus"
    tell first document window of front document
		set SelectedItemInMainView to selected trees of content
		set theSelectedTask to value of item 1 of SelectedItemInMainView
		--flag item
		set flagged of theSelectedTask to true
		--Set time back to 12 of today
		set theDate to (current date) - (time of (current date))
		--then add 17 hours
		set the time of theDate to 61200
		--set the start date
		set the start date of theSelectedTask to theDate
		try
			set context of theSelectedTask to context "Home"
		end try
	end tell
end tell
https://snipt.net/embed/6412b4cbb0fa499d9421bc67cc9ff373/
/raw/6412b4cbb0fa499d9421bc67cc9ff373/
6412b4cbb0fa499d9421bc67cc9ff373
applescript
AppleScript
1
2019-06-17T23:41:10
True
False
False
/api/public/snipt/40843/
applescript-for-modifying-selected-omnifocus-task
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">tell</span> <span class="nb">application</span> <span class="s2">&quot;OmniFocus&quot;</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">tell</span> <span class="nb">first</span> <span class="na">document</span> <span class="na">window</span> <span class="k">of</span> <span class="nb">front</span> <span class="na">document</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">set</span> <span class="nv">SelectedItemInMainView</span> <span class="k">to</span> <span class="nv">selected</span> <span class="nv">trees</span> <span class="k">of</span> <span class="na">content</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">set</span> <span class="nv">theSelectedTask</span> <span class="k">to</span> <span class="nv">value</span> <span class="k">of</span> <span class="nb">item</span> <span class="mi">1</span> <span class="k">of</span> <span class="nv">SelectedItemInMainView</span> </span><span id="L-5"><a name="L-5"></a> <span class="c">--flag item</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">set</span> <span class="nv">flagged</span> <span class="k">of</span> <span class="nv">theSelectedTask</span> <span class="k">to</span> <span class="no">true</span> </span><span id="L-7"><a name="L-7"></a> <span class="c">--Set time back to 12 of today</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">set</span> <span class="nv">theDate</span> <span class="k">to</span> <span class="p">(</span><span class="nb">current date</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="nv">time</span> <span class="k">of</span> <span class="p">(</span><span class="nb">current date</span><span class="p">))</span> </span><span id="L-9"><a name="L-9"></a> <span class="c">--then add 17 hours</span> </span><span id="L-10"><a name="L-10"></a> <span class="k">set</span> <span class="nb">the</span> <span class="nv">time</span> <span class="k">of</span> <span class="nv">theDate</span> <span class="k">to</span> <span class="mi">61200</span> </span><span id="L-11"><a name="L-11"></a> <span class="c">--set the start date</span> </span><span id="L-12"><a name="L-12"></a> <span class="k">set</span> <span class="nb">the</span> <span class="nb">start</span> <span class="nv">date</span> <span class="k">of</span> <span class="nv">theSelectedTask</span> <span class="k">to</span> <span class="nv">theDate</span> </span><span id="L-13"><a name="L-13"></a> <span class="k">try</span> </span><span id="L-14"><a name="L-14"></a> <span class="k">set</span> <span class="na">context</span> <span class="k">of</span> <span class="nv">theSelectedTask</span> <span class="k">to</span> <span class="na">context</span> <span class="s2">&quot;Home&quot;</span> </span><span id="L-15"><a name="L-15"></a> <span class="k">end</span> <span class="k">try</span> </span><span id="L-16"><a name="L-16"></a> <span class="k">end</span> <span class="k">tell</span> </span><span id="L-17"><a name="L-17"></a><span class="k">end</span> <span class="k">tell</span> </span></pre></div> </td></tr></table>

AppleScript

Sample code to add a context and flag an OmniFocus task

tell application "OmniFocus"
    tell front document
		set myTaskName to "Sample Task"
		set myContext to context "Phone"
		set theTask to make new inbox task with properties {name:myTaskName, context:myContext}
		tell theTask
			set flagged to true
		end tell
	end tell
end tell
https://snipt.net/embed/8fc1e22f17575a91d7b8026a6f4d597b/
/raw/8fc1e22f17575a91d7b8026a6f4d597b/
8fc1e22f17575a91d7b8026a6f4d597b
applescript
AppleScript
1
2019-06-13T01:38:30
True
False
False
/api/public/snipt/40839/
sample-code-to-add-a-context-and-flag-an-omnifocus-task
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">tell</span> <span class="nb">application</span> <span class="s2">&quot;OmniFocus&quot;</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">tell</span> <span class="nb">front</span> <span class="na">document</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">set</span> <span class="nv">myTaskName</span> <span class="k">to</span> <span class="s2">&quot;Sample Task&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">set</span> <span class="nv">myContext</span> <span class="k">to</span> <span class="na">context</span> <span class="s2">&quot;Phone&quot;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">set</span> <span class="nv">theTask</span> <span class="k">to</span> <span class="nb">make</span> <span class="nb">new</span> <span class="nv">inbox</span> <span class="nv">task</span> <span class="nv">with</span> <span class="na">properties</span> <span class="p">{</span><span class="na">name</span><span class="p">:</span><span class="nv">myTaskName</span><span class="p">,</span> <span class="na">context</span><span class="p">:</span><span class="nv">myContext</span><span class="p">}</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">tell</span> <span class="nv">theTask</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">set</span> <span class="nv">flagged</span> <span class="k">to</span> <span class="no">true</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">end</span> <span class="k">tell</span> </span><span id="L-9"><a name="L-9"></a> <span class="k">end</span> <span class="k">tell</span> </span><span id="L-10"><a name="L-10"></a><span class="k">end</span> <span class="k">tell</span> </span></pre></div> </td></tr></table>

AppleScript

Strip formatting from clipboard content and paste

1
2
3
4
5
--By Don Southard aka @binaryghost
do shell script ("clip=`pbpaste`;tmp=`mktemp -t cp`.txt;echo $clip > $tmp;cat $tmp | pbcopy")
tell application id "com.apple.systemevents"
	keystroke "v" using {command down}
end tell
https://snipt.net/embed/ee92e4e72e004db96710281d199bf2b1/
/raw/ee92e4e72e004db96710281d199bf2b1/
ee92e4e72e004db96710281d199bf2b1
applescript
AppleScript
5
2019-06-08T19:35:04
True
False
False
/api/public/snipt/29607/
strip-formatting-from-clipboard-content-and-paste
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c">--By Don Southard aka @binaryghost</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">do shell script</span> <span class="p">(</span><span class="s2">&quot;clip=`pbpaste`;tmp=`mktemp -t cp`.txt;echo $clip &gt; $tmp;cat $tmp | pbcopy&quot;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="k">tell</span> <span class="nb">application</span> <span class="na">id</span> <span class="s2">&quot;com.apple.systemevents&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">keystroke</span> <span class="s2">&quot;v&quot;</span> <span class="nv">using</span> <span class="p">{</span><span class="nv">command</span> <span class="nv">down</span><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="k">end</span> <span class="k">tell</span> </span></pre></div> </td></tr></table>
applescript