1. 程式人生 > 實用技巧 >嘿Siri,我的血糖是多少? 學習使用Apple的iPhone快捷方式進行編碼

嘿Siri,我的血糖是多少? 學習使用Apple的iPhone快捷方式進行編碼

A library of dozens of shortcuts on iOS

Bear with me here. Apple Shortcuts (free on the App Store) is extraordinary and you shouldn't sleep on it. In fact, you should use it and explore it as it's amazing. I would go even further and say it could be a great place to learn to code!

在這裡忍受我。 Apple快捷鍵(在App Store上免費提供)非常出色,您不應該沉迷於此。 實際上,您應該使用它並對其進行探索,因為它很棒。 我走得更遠,說這可能是學習編碼的好地方!

Apple Shortcuts on iPhone is a lot like Microsoft Flow, except for your phone. Shortcuts let you string together Actions (ahem, functions) into multi-step tasks (ahem, functions that call functions). There's a rich and growing gallery of shortcuts that you can copy into your local (to your phone) library. You can then name them and invoke your Shortcuts with Siri.

iPhone上的Apple快捷方式與Microsoft Flow非常相似,但手機除外。 快捷方式使您可以將動作(Ahem,函式)組合成多步任務(Ahem,呼叫函式的函式)。 您可以將豐富的快捷方式庫複製到本地(到電話)庫中。 然後,您可以命名它們並使用Siri呼叫快捷方式。

Here's a few links to Shortcuts that (assuming you are reading this from your iPhone) you can add to your library with a click!

這裡是指向快捷方式的一些連結(假設您正在從iPhone中讀取內容),只需單擊即可新增到您的媒體庫中!

Once you have a shortcut you can invoke it as an item/icon on your springboard/home screen, you can have Siri run it with your voice, or invoke it via a "share sheet" that is available in all apps.

一旦有了快捷方式,您就可以在跳板/主螢幕上將其作為項/圖示來呼叫,您可以讓Siri用您的聲音執行它,或者通過所有應用程式中可用的“共享表”來呼叫它。

It would be reasonable to think this was a simple macro system with a few basic building blocks, but I don't think Apple's team gets enough credit. This is a complete development environment on your phone.

認為這是一個具有幾個基本構建塊的簡單巨集系統是合理的,但我認為Apple的團隊沒有獲得足夠的信譽。 這是您手機上的完整開發環境。

For example, here's a incredibly intricate and powerful Shortcut if one is pulled over by the police.

例如,如果有人被警察拖走,這是一個極其複雜而強大的快捷方式

It pauses any music that may be playing, turns down your brightness and volume, turns on Do Not Disturb, and sends a message to the contact of your choosing letting them know you’re being pulled over and what your current location is. It then opens your front camera and starts a video recording so you have a video record of being pulled over.

它會暫停可能正在播放的音樂,降低亮度和音量,開啟“請勿打擾”,並向您選擇的聯絡人傳送一條訊息,讓他們知道您被拉住了,以及您當前所在的位置。 然後,它將開啟您的前置攝像頭並開始視訊錄製,因此您會被拉下視訊記錄。

Once you stop the recording it sends a copy of the video to a contact you specify, puts volume and brightness back to where they were, turns off Do Not Disturb, and gives you the option to send to iCloud Drive or Dropbox!

停止錄製後,它會將視訊的副本傳送到您指定的聯絡人,將音量和亮度恢復到原來的狀態,關閉“請勿打擾”,並提供傳送到iCloud Drive或Dropbox的選項!

You could then record a Siri shortcut and just say "Hey Siri, I'm being pulled over" and all this happens automatically, hands free.

然後,您可以記錄Siri快捷方式,然後說“嘿Siri,我被拉了過來”,所有這些都會自動發生,擴音。

Take a look at the Laundry Timer app here. It's a very classic "take input and do a thing" program. You can build and extend workflows like this and the data from one flows through to the next one.

在這裡檢視洗衣計時器應用程式。 這是一個非常經典的“接受輸入並做某事”程式。 您可以像這樣構建和擴充套件工作流程,並且資料從一個流向另一個。

A multiple step shortcut with many actions that flow data into the next, organized in a pipeline

Note the Shortcut above. The "Adjust Date" action pops up a Date and is used as a Diff(erence) against the "Current Date" action, then used again in the Add New Reminder as an input to "Add New Reminder." These contextual variables flow through and are easily accessible in this genius UI. It really is near-perfect. Try it.

請注意上面的快捷方式。 “調整日期”操作會彈出一個日期,並用作與“當前日期”操作的差異,然後在“新增新提醒”中再次用作“新增新提醒”的輸入。 這些上下文變數流經此天才UI並很容易訪問。 確實是近乎完美的。 試試吧。

At this point you may be thinking, um, OK, that's cute, but where's the learn to code revolution here? It's not that open-ended of a system, what can I really do?

在這一點上,您可能會想,嗯,好吧,這很可愛,但是在這裡學習編碼革命的地方在哪裡? 不是系統的開放性,我該怎麼辦?

Like many connected cars, my car has a kind of REST API that its app uses to do things like heat up the climate system. Here I can literally POST (like Curl, but on your iPhone!) to an endpoint and pass in a FORM and parse the resulting JSON. Wow! Drink that in. You can write complex functions with iOS Shortcuts. Really.

像許多聯網汽車一樣,我的汽車具有一種REST API,其應用程式可用來執行諸如加熱氣候系統之類的事情。 在這裡,我可以按字面意義將POST(例如Curl,但在您的iPhone上!)釋出到端點並傳遞FORM並解析生成的JSON。 哇! 喝點東西。您可以使用iOS快捷方式編寫複雜的功能。 真。

calling a REST API with an iOS shortcut

Hang on. My body has a REST API. I use the open source Nightscout project to create a REST API on top of my Diabetes Continuous Glucose Meter then surface it in places like my lighted keyboard or even my Git Prompt.

不掛斷。 我的身體有一個REST API。 我使用開源Nightscout專案在“糖尿病連續血糖儀”的頂部建立REST API,然後將其放置在照明鍵盤Git Prompt之類的地方

How hard would it be to - right now as I make this blog post - write a method to have Siri retrieve my blood sugar and announce it to me when I say "Siri what's my blood sugar?" Let's see!

現在,當我撰寫此部落格文章時,要寫出一種方法讓Siri檢索我的血糖並在我說“ Siri血糖是多少”時向我宣佈這將是多麼困難。 讓我們來看看!

I make a URL object with my REST API that returns my sugar as JSON, it gets passed into Get Contents of URL. That makes a Dictionary from the Input, then gets the value of "sgv" (serum glucose value) and then the result of that is used to make a string with the Text action.

我使用我的REST API製作了一個URL物件,該物件以糖的形式返回JSON,並將其傳遞給Get URLs。 從輸入中建立字典,然後獲取“ sgv”(血清葡萄糖值)的值,然後將其結果用於通過“文字”操作生成字串。

Preparing to make a shortcut

Now I have Siri SAY it. I can "debug" by running the Shortcut with the play button.

現在我有Siri說了。 我可以通過使用播放按鈕執行快捷方式來“除錯”。

Building a shortcut

Then I can Add it to Siri and record my phrase. Here's me saying "what's my blood sugar" and she's telling me. Yes, I know. I had a cookie. I deserved it.

然後,我可以將其新增到Siri並記錄我的短語。 這是我在說“我的血糖是多少”,她在告訴我。 是的我知道。 我有一個餅乾。 我應得的

Running your shortcut

This is just the start. It could also tell me my trend lines, text someone if it's high, make a chart, I figure can do anything! I'm going to continue to explore Shortcuts but this little NightScout one can be downloaded to YOUR phone here. You'll only need to put in YOUR own URL for your Nightscout instance.

這只是開始。 它也可以告訴我我的趨勢線,發簡訊給某人,如果它很高,繪製圖表,我想做任何事! 我將繼續探索“快捷方式”,但是可以在這裡將這個NightScout小程式下載到您的手機中。 您只需要為Nightscout例項輸入您自己的URL。



Sponsor: Manage GitHub Pull Requests right from the IDE with the latest JetBrains Rider. An integrated performance profiler on Windows comes to the rescue as well.

贊助商:使用最新的JetBrains Rider從IDE直接管理GitHub Pull Requests。 Windows上的整合效能分析器也可以解決。

關於斯科特 (About Scott)

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

斯科特·漢塞爾曼(Scott Hanselman)是前教授,前金融首席架構師,現在是演講者,顧問,父親,糖尿病患者和Microsoft員工。 他是一位失敗的單口相聲漫畫家,一個玉米種植者和一本書的作者。

facebook twitter subscribe About 關於 Newsletter 時事通訊 Hosting By 主持人 Hosted in an Azure App Service

翻譯自: https://www.hanselman.com/blog/hey-siri-whats-my-blood-sugar-learning-to-code-with-apples-iphone-shortcuts