Skip to content

Instantly share code, notes, and snippets.

@fish2000
Last active February 1, 2020 04:02
Show Gist options
  • Save fish2000/e36f650a4d5480be649e1ebe92c2f207 to your computer and use it in GitHub Desktop.
Save fish2000/e36f650a4d5480be649e1ebe92c2f207 to your computer and use it in GitHub Desktop.
All the help for all the options for TextMate 2’s “Dialog2” command
#!/usr/bin/env bash
DIALOG="/Applications/TextMate.app/Contents/PlugIns/Dialog2.tmplugin/Contents/Resources/tm_dialog2"
$DIALOG help
# usage: "$DIALOG" [--version] <command> [<args>]
# 10 commands registered:
# alert: Show an alert box.
# defaults: Register default values for user settings.
# filepanel: Shows an open file/folder or save file panel.
# help: Gives a brief list of available commands, or usage details for a specific command.
# images: Add image files as named images for use by other commands/nibs.
# menu: Presents a menu using the given structure and returns the option chosen by the user
# nib: Displays custom dialogs from NIBs.
# popup: Presents the user with a list of items which can be filtered down by typing to select the item they want.
# prototype: Register classes for use with NSArrayController.
# tooltip: Shows a tooltip at the caret with the provided content, optionally rendered as HTML.
# Use `"$DIALOG" help <command>` for detailed help.
echo ""
$DIALOG help alert
# Show an alert box.
#
# alert usage:
# "$DIALOG" alert --alertStyle warning --title 'Delete File?' --body 'You cannot undo this action.' --button1 Delete --button2 Cancel
echo ""
$DIALOG help defaults
# Register default values for user settings.
#
# defaults usage:
# "$DIALOG" defaults --register '{ webOutputTheme = night; }'
echo ""
$DIALOG help filepanel
# Shows an open file/folder or save file panel.
#
# filepanel usage:
# "$DIALOG" filepanel --title Title --prompt Prompt --message Message --defaultDirectory '~/Desktop' showsHiddenFiles 1
# "$DIALOG" filepanel --isSavePanel --title 'Save Me' --label 'Label:' --filename 'test.txt' --allowedFileTypes '(txt,tab)'
#
# Options:
# --allowedFileTypes «plist array of allowed file types or a single string»
# e.g. --allowedFileTypes pdf
# --allowedFileTypes '(txt,tab)'
# --allowsMultipleSelection {1,0} [not in 'isSavePanel' mode]
# --allowsOtherFileTypes {1,0}
# --canChooseDirectories {1,0}
# --canChooseFiles {1,0}
# --canCreateDirectories {1,0}
# --defaultDirectory «valid directory path»
# default directory for panel, if not passed the last visited one will be used
# --filename «default file name» [only in 'isSavePanel' mode]
# --isSavePanel
# if passed shows a save file panel otherwise an open file panel
# --label «a label» [only in 'isSavePanel' mode]
# default 'Save As:'
# --message «a message»
# --prompt «a prompt»
# action button title - default 'Open' or 'Save' for isSavePanel mode
# --showsHiddenFiles {1,0}
# --title «a title»
# window title - default 'Open' or 'Save' for isSavePanel mode
# --treatsFilePackagesAsDirectories {1,0}
echo ""
$DIALOG help images
# Add image files as named images for use by other commands/nibs.
#
# images usage:
# "$DIALOG" images --register "{ macro = '$(find_app com.macromates.textmate)/Contents/Resources/Bundle Item Icons/Macros.png'; }"
echo ""
$DIALOG help menu
# Presents a menu using the given structure and returns the option chosen by the user
#
# menu usage:
# "$DIALOG" menu --items '({title = foo;}, {separator = 1;}, {header=1; title = bar;}, {title = baz;})'
echo ""
$DIALOG help nib
# Displays custom dialogs from NIBs.
#
# nib usage:
# "$DIALOG" nib --load «nib file» [«options»]
# "$DIALOG" nib --update «token» [«options»]
# "$DIALOG" nib --wait «token»
# "$DIALOG" nib --dispose «token»
# "$DIALOG" nib --list
#
# The nib will be disposed after user closes its window unless --wait is being used.
#
# Options:
# --center
# --model «plist»
echo ""
$DIALOG help popup
# Presents the user with a list of items which can be filtered down by typing to select the item they want.
#
# popup usage:
# "$DIALOG" popup --suggestions '( { display = law; }, { display = laws; insert = "(${1:hello}, ${2:again})"; } )'
echo ""
$DIALOG help prototype
# Register classes for use with NSArrayController.
#
# prototype usage:
# "$DIALOG" prototype --register "{ SQL_New_Connection = { title = untitled; serverType = MySQL; hostName = localhost; userName = '$LOGNAME'; }; }"
# "$DIALOG" prototype --show SQL_New_Connection
echo ""
$DIALOG help tooltip
# Shows a tooltip at the caret with the provided content, optionally rendered as HTML.
#
# tooltip usage:
# "$DIALOG" tooltip --text 'regular text'
# "$DIALOG" tooltip --html '<some>html</some>'
# Use --transparent to give the tooltip window a transparent background
echo ""
find_app com.macromates.textmate # … q.v. “find_app.cc” source sub.
# /Applications/TextMate.app
/// find_app.cc - extracted from the TextMate 2 source - revised by fish2000
#include <unistd.h>
#include <cstdio>
#include <ApplicationServices/ApplicationServices.h>
static char const* const AppVersion = "1.1";
int main(int argc, char const* argv[]) {
if (argc == 2 && std::strncmp("-", argv[1], 1) != 0) {
CFStringRef bundleID = NULL;
CFStringRef appName = NULL;
if (std::strstr(argv[1], ".app")) {
appName = CFStringCreateWithBytes(kCFAllocatorDefault,
(UInt8*)argv[1],
std::strlen(argv[1]),
kCFStringEncodingUTF8, FALSE);
} else {
bundleID = CFStringCreateWithBytes(kCFAllocatorDefault,
(UInt8*)argv[1],
std::strlen(argv[1]),
kCFStringEncodingUTF8, FALSE);
}
CFURLRef url = NULL;
if (noErr == LSFindApplicationForInfo(kLSUnknownCreator, bundleID, appName, NULL, &url)) {
CFStringRef str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
CFIndex len = CFStringGetLength(str);
UInt8 buf[4 * len];
CFIndex actualLength = 0;
if (len == CFStringGetBytes(str,
(CFRange){0, len},
kCFStringEncodingUTF8,
'?', FALSE, buf, sizeof(buf),
&actualLength)) {
::write(STDOUT_FILENO, buf, actualLength);
return 0;
}
}
} else {
std::fprintf(stderr, "find_app %s: print full path to application\n"
"usage: find_app bundle_identifier\n"
" find_app application_name.app\n", AppVersion);
}
return 1;
}
@fish2000
Copy link
Author

fish2000 commented Feb 1, 2020

The reason this is here is because just running this command from the prompt is ineffective – it errors out with a pithy message about not being able to find some server – so to get the help text you have to run this sort of bash script from inside TextMate. In a nutshell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment