-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
Common.h
259 lines (215 loc) · 11.7 KB
/
Common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
Copyright (c) 2003-2024, Sveinbjorn Thordarson <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
// General program information
#define PROGRAM_NAME @"Platypus"
#define PROGRAM_VERSION @"5.4.2"
#define PROGRAM_CREATOR_STAMP [NSString stringWithFormat:@"%@-%@", PROGRAM_NAME, PROGRAM_VERSION]
#define PROGRAM_MIN_SYS_VERSION @"10.13.0"
#define PROGRAM_BUNDLE_IDENTIFIER [NSString stringWithFormat:@"org.sveinbjorn.%@", PROGRAM_NAME]
#define PROGRAM_AUTHOR @"Sveinbjorn Thordarson"
#define PROGRAM_WEBSITE @"https://sveinbjorn.org/platypus"
#define PROGRAM_GITHUB_WEBSITE @"https://github.com/sveinbjornt/Platypus"
#define PROGRAM_DONATIONS @"https://sveinbjorn.org/donations"
#define PROGRAM_PROFILE_UTI @"org.sveinbjorn.platypus.profile"
#define PROGRAM_PROFILE_SUFFIX @"platypus"
#define PROGRAM_MANPAGE @"platypus.man.html"
#define PROGRAM_LICENSE_FILE @"License.html"
#define PROGRAM_DOCUMENTATION @"Documentation.html"
#define PROGRAM_MANPAGE_URL @"https://sveinbjorn.org/files/manpages/platypus.man.html"
#define PROGRAM_DOCUMENTATION_URL @"https://sveinbjorn.org/files/manpages/PlatypusDocumentation.html"
#define PROGRAM_UTI_INFORMATION_URL @"https://en.wikipedia.org/wiki/Uniform_Type_Identifier"
// Folders
#define PROGRAM_APP_SUPPORT_PATH [[NSString stringWithFormat:@"~/Library/Application Support/%@/", PROGRAM_NAME] stringByExpandingTildeInPath]
#define PROGRAM_TEMPDIR_PATH [NSString stringWithFormat:@"%@/", PROGRAM_APP_SUPPORT_PATH]
#define PROGRAM_PROFILES_PATH [NSString stringWithFormat:@"%@/Profiles/", PROGRAM_APP_SUPPORT_PATH]
#define PROGRAM_EXAMPLES_PATH [NSString stringWithFormat:@"%@/Examples/", [[NSBundle mainBundle] resourcePath]]
#define NEW_SCRIPT_FILENAME @"Script"
// Command line tool seetings
#define CMDLINE_PROGNAME_BUNDLE @"platypus_clt.gz"
#define CMDLINE_PROGNAME @"platypus"
#define CMDLINE_SCRIPTEXEC_BIN_NAME @"ScriptExec"
#define CMDLINE_SCRIPTEXEC_GZIP_NAME @"ScriptExec.gz"
#define CMDLINE_MANPAGE_NAME @"platypus.1.gz"
#define CMDLINE_DEFAULT_ICON_NAME @"PlatypusDefault.icns"
#define CMDLINE_NIB_NAME @"MainMenu.nib"
#define CMDLINE_NIB_OPT_NAME @"MainMenu-optimized.nib"
#define CMDLINE_VERSION_ARG_FLAG @"--version"
#define CMDLINE_BASE_INSTALL_PATH @"/usr/local"
#define CMDLINE_BIN_PATH @"/usr/local/bin"
#define CMDLINE_TOOL_PATH @"/usr/local/bin/platypus"
#define CMDLINE_SHARE_PATH @"/usr/local/share/platypus"
#define CMDLINE_MANDIR_PATH @"/usr/local/share/man/man1"
#define CMDLINE_MANPAGE_PATH @"/usr/local/share/man/man1/platypus.1.gz"
#define CMDLINE_NIB_PATH @"/usr/local/share/platypus/MainMenu.nib"
#define CMDLINE_SCRIPT_EXEC_PATH @"/usr/local/share/platypus/ScriptExec"
#define CMDLINE_ARG_SEPARATOR @"|"
#define IBTOOL_PATH @"/usr/bin/ibtool"
#define PERL_PATH @"/usr/bin/perl"
#define CODESIGN_PATH @"/usr/bin/codesign"
#define APPBUNDLE_SUFFIX @".app"
#define GZIP_SUFFIX @".gz"
#define DEFAULT_TEXT_FONT_NAME @"Monaco"
#define DEFAULT_TEXT_FONT_SIZE 13.0
#define DEFAULT_TEXT_FG_COLOR @"#000000"
#define DEFAULT_TEXT_BG_COLOR @"#ffffff"
#define DEFAULT_TEXT_ENCODING NSUTF8StringEncoding
#define DEFAULT_EDITOR @"Built-In"
#define DEFAULT_INTERPRETER_PATH @"/bin/sh"
#define DEFAULT_VERSION @"1.0"
#define DEFAULT_APP_NAME @"Application"
#define DEFAULT_DESTINATION_PATH [[NSString stringWithFormat:@"~/Desktop/%@.app", DEFAULT_APP_NAME] stringByExpandingTildeInPath]
#define DEFAULT_SCRIPT_TYPE @"sh"
#define DEFAULT_SUFFIXES @[]
#define DEFAULT_UTIS @[(NSString *)kUTTypeItem, (NSString *)kUTTypeFolder]
#define DEFAULT_URI_PROTOCOLS @[]
#define DEFAULT_STATUS_ITEM_TITLE @"Title"
#define SHELL_COMMAND_STRING_FONT [NSFont userFixedPitchFontOfSize:11.0]
// Notifications
#define PLATYPUS_APP_SPEC_CREATION_NOTIFICATION @"PlatypusAppSpecCreationNotification"
#define PLATYPUS_APP_SIZE_CHANGED_NOTIFICATION @"PlatypusAppSizeChangedNotification"
// Status Item display types
#define PLATYPUS_STATUSITEM_DISPLAY_TYPE_TEXT @"Text"
#define PLATYPUS_STATUSITEM_DISPLAY_TYPE_ICON @"Icon"
#define PLATYPUS_STATUSITEM_DISPLAY_TYPE_DEFAULT PLATYPUS_STATUSITEM_DISPLAY_TYPE_TEXT
// Execution style
typedef enum PlatypusExecStyle {
PlatypusExecStyle_Normal = 0,
PlatypusExecStyle_Authenticated = 1
} PlatypusExecStyle;
// Status item style
typedef enum PlatypusStatusItemStyle {
PlatypusStatusItemStyle_Title = 0,
PlatypusStatusItemStyle_Icon = 1
} PlatypusStatusItemStyle;
// Interface type
typedef enum PlatypusInterfaceType {
PlatypusInterfaceType_None = 0,
PlatypusInterfaceType_ProgressBar = 1,
PlatypusInterfaceType_TextWindow = 2,
PlatypusInterfaceType_WebView = 3,
PlatypusInterfaceType_StatusMenu = 4,
PlatypusInterfaceType_Droplet = 5
} PlatypusInterfaceType;
// Array of interface type name strings
// mapped to PlatypusInterfaceType enum
#define PLATYPUS_INTERFACE_TYPE_NAMES @[\
@"None", \
@"Progress Bar", \
@"Text Window", \
@"Web View", \
@"Status Menu", \
@"Droplet" \
]
#define DEFAULT_INTERFACE_TYPE PlatypusInterfaceType_TextWindow
#define DEFAULT_INTERFACE_TYPE_STRING PLATYPUS_INTERFACE_TYPE_NAMES[DEFAULT_INTERFACE_TYPE]
#define IsValidInterfaceType(X) ( (X) >= 0 && (X) < [PLATYPUS_INTERFACE_TYPE_NAMES count] )
#define IsValidInterfaceTypeString(X) [PLATYPUS_INTERFACE_TYPE_NAMES containsObject:(X)]
#define InterfaceTypeForString(X) (PlatypusInterfaceType)[PLATYPUS_INTERFACE_TYPE_NAMES indexOfObject:(X)]
#define IsTextStyledInterfaceType(X) ( (X) == PlatypusInterfaceType_ProgressBar || \
(X) == PlatypusInterfaceType_TextWindow || \
(X) == PlatypusInterfaceType_StatusMenu )
#define IsTextStyledInterfaceTypeString(X) IsTextStyledInterfaceType(InterfaceTypeForString(X))
#define IsTextSizableInterfaceType(X) ( (X) == PlatypusInterfaceType_ProgressBar || \
(X) == PlatypusInterfaceType_TextWindow || \
(X) == PlatypusInterfaceType_WebView )
#define IsTextViewScrollableInterfaceType(X) ( (X) == PlatypusInterfaceType_ProgressBar || \
(X) == PlatypusInterfaceType_TextWindow )
// App Spec keys
extern NSString * const AppSpecKey_Creator;
extern NSString * const AppSpecKey_ExecutablePath;
extern NSString * const AppSpecKey_NibPath;
extern NSString * const AppSpecKey_DestinationPath;
extern NSString * const AppSpecKey_Overwrite;
extern NSString * const AppSpecKey_SymlinkFiles;
extern NSString * const AppSpecKey_StripNib;
extern NSString * const AppSpecKey_Name;
extern NSString * const AppSpecKey_ScriptPath;
extern NSString * const AppSpecKey_InterfaceType;
extern NSString * const AppSpecKey_IconPath;
extern NSString * const AppSpecKey_InterpreterPath;
extern NSString * const AppSpecKey_InterpreterArgs;
extern NSString * const AppSpecKey_ScriptArgs;
extern NSString * const AppSpecKey_Version;
extern NSString * const AppSpecKey_Identifier;
extern NSString * const AppSpecKey_Author;
extern NSString * const AppSpecKey_Droppable;
extern NSString * const AppSpecKey_Authenticate;
extern NSString * const AppSpecKey_RemainRunning;
extern NSString * const AppSpecKey_RunInBackground;
extern NSString * const AppSpecKey_SendNotifications;
extern NSString * const AppSpecKey_BundledFiles;
extern NSString * const AppSpecKey_Suffixes;
extern NSString * const AppSpecKey_Utis;
extern NSString * const AppSpecKey_URISchemes;
extern NSString * const AppSpecKey_AcceptText;
extern NSString * const AppSpecKey_AcceptFiles;
extern NSString * const AppSpecKey_Service;
extern NSString * const AppSpecKey_PromptForFile;
extern NSString * const AppSpecKey_DocIconPath;
extern NSString * const AppSpecKey_TextFont;
extern NSString * const AppSpecKey_TextSize;
extern NSString * const AppSpecKey_TextColor;
extern NSString * const AppSpecKey_TextBackgroundColor;
extern NSString * const AppSpecKey_StatusItemDisplayType;
extern NSString * const AppSpecKey_StatusItemTitle;
extern NSString * const AppSpecKey_StatusItemIcon;
extern NSString * const AppSpecKey_StatusItemUseSysfont;
extern NSString * const AppSpecKey_StatusItemIconIsTemplate;
extern NSString * const AppSpecKey_IsExample; // examples only
extern NSString * const AppSpecKey_ScriptText; // examples only
extern NSString * const AppSpecKey_ScriptName; // examples only
extern NSString * const AppSpecKey_DocIconPath_Legacy; // legacy
extern NSString * const AppSpecKey_InterpreterPath_Legacy; // legacy
extern NSString * const AppSpecKey_InterfaceType_Legacy; // legacy
extern NSString * const AppSpecKey_RunInBackground_Legacy; // legacy
extern NSString * const AppSpecKey_SigningIdentity;
// NSUserDefaults keys for Platypus app
extern NSString * const DefaultsKey_BundleIdentifierPrefix;
extern NSString * const DefaultsKey_DefaultEditor;
extern NSString * const DefaultsKey_RevealApplicationWhenCreated;
extern NSString * const DefaultsKey_OpenApplicationWhenCreated;
extern NSString * const DefaultsKey_DefaultAuthor;
extern NSString * const DefaultsKey_SymlinkFiles;
extern NSString * const DefaultsKey_StripNib;
extern NSString * const DefaultsKey_EditorFontSize;
extern NSString * const DefaultsKey_EditorWordWrap;
extern NSString * const DefaultsKey_Launched;
extern NSString * const DefaultsKey_SigningIdentity;
// NSUserDefaults keys for ScriptExec app
extern NSString * const ScriptExecDefaultsKey_UserFontSize;
extern NSString * const ScriptExecDefaultsKey_ShowDetails;
// Abbreviations. Objective-C is often tediously verbose
#define FILEMGR [NSFileManager defaultManager]
#define DEFAULTS [NSUserDefaults standardUserDefaults]
#define WORKSPACE [NSWorkspace sharedWorkspace]
// Logging
#ifdef DEBUG
#define DLog(...) NSLog(__VA_ARGS__)
#else
#define DLog(...)
#endif
// Prototypes
extern BOOL UTTypeIsValid(NSString *inUTI);
extern BOOL BundleIdentifierIsValid(NSString *bundleIdentifier);