Skip to content

Instantly share code, notes, and snippets.


Tommie N. Carter, Jr., BSIT, MBA mingsai

View GitHub Profile
mingsai /
Created May 28, 2020
Applescript: Debugging variables
Displaying variables
The display command is how you produce a text version of the contents of any variable. Various commands display text, making it natural to display information about the run while a script is executing.
quietmsg(s): displays the string s in the console,
msg(s): like quietmsg(s), but brings the console to the front,
postit s displays a message in the floating Message window. postit "" closes the floating Message window.
postit "job in progress …"
set x to 1
set x to x + 1
mingsai / trim_last_3_chars.applescript
Created May 28, 2020
Applescript: Trim the last three characters from text input
View trim_last_3_chars.applescript
on run {input, parameters}
set output to ((characters 1 thru -4 of (item 1 of input as string)) as string)
--set output to (item 1 of input as string)
(* Your script goes here *)
(* if output ends with ".js" then
set output to ((characters 1 thru -4 of output) as string)
--display dialog updated
end if
--display dialog output
mingsai / trim_string_sample.applescript
Created May 28, 2020
Applescript: Trim text front and back example
View trim_string_sample.applescript
set whichFile to choose file with multiple selections allowed
repeat with aFile in whichFile
tell application "Finder"
set filename to name of aFile
set name of aFile to ((characters 4 thru -1 of filename) as string) --trim first 3
--set name of whichFile to ((characters 1 thru -4 of filename) as string) --trim last 3
end tell
end repeat
mingsai / replace_handler.applescript
Created May 28, 2020
Applescript: Replace text handler
View replace_handler.applescript
-- Replaces a substring with another substring
set my_var to StringsLib's replace_text(some_text, "abc", "def")
on replace_text(this_text, search_string, replacement_string)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
mingsai / string_escaping.applescript
Last active May 28, 2020
Applescript - Escaping double quotes around variable text
View string_escaping.applescript
set myString to "This is a \"quoted\" text."
Sample usgage:
on run {input, parameters}
set filename to item 1 of input
set desc to "\"" & item 2 of input & "\""
--display dialog filename & desc
mingsai / variable_to_bash.txt
Last active May 28, 2020
Applescript - pass variables to the terminal shell
View variable_to_bash.txt
Applescript: Run or Call a Shell Script
How do run a shell script with an AppleScript? How do I integrate shell scripts into AppleScript?
How do I call a shell script called /path/to/ using an applescript?
AppleScript is a scripting for Mac OS. It is the Mac OS scripting interface, which is meant to operate in parallel with the graphical user interface. With AppleScript, you can control, and communicate among, applications, databases, networks, Web services, and even the operating system itself.
Running Shell Commands From AppleScript Scripts
You can easily execute shell commands from your AppleScript using the following syntax:
View gem_doc_management.txt
Gem installs can be slooow. One of the biggest culprits is documentation. Every time you install a gem, your computer has to scan the source of that gem and generate documentation.
This can be useful if you often need to check gem documentation when you're offline. Just run gem server and point your browser at http://localhost:8808 to access them. The ri command is also handy to search documentation from the terminal.
But if you're like me, you probably don't use local docs. You probably have a decent internet connection at most times. So the time spent generating documentation is just time wasted.
If you're using bundler to install all of your gems, you don't have to do anything. Bundler skips rdoc/ri by default. If you happen to be using the gem command directly, you'll need to do a bit of configuration.
You may already know that you can disable rdoc/ri generation when you run gem install, by passing in certain flags.
View alert_dialog_example.dart
import 'package:flutter/material.dart';
Future<void> _ackAlert(BuildContext context) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Not in stock'),
content: const Text('This item is no longer available'),
actions: <Widget>[
View iap_init.dart
// Subscribe to any incoming purchases at app initialization. These can
// propagate from either storefront so it's important to listen as soon as
// possible to avoid losing events.
class _MyAppState extends State<MyApp> {
StreamSubscription<List<PurchaseDetails>> _subscription;
void initState() {
final Stream purchaseUpdates =
View iap_doc.txt
In App Purchase
A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store (on iOS) and Google Play (on Android).
Add this to your Flutter app to:
Show in app products that are available for sale from the underlying shop. Includes consumables, permanent upgrades, and subscriptions.
Load in app products currently owned by the user according to the underlying shop.
Send your user to the underlying store to purchase your products.
Getting Started
You can’t perform that action at this time.