-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExample3ConfigMixedJS.applescript
123 lines (113 loc) · 9.57 KB
/
Example3ConfigMixedJS.applescript
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
// This example loads script "PashuaJS.scpt" (to be compiled from "PashuaJS.applescript") from
//
// ~/Library/Script Libraries/
//
// To view this folder, choose the Finder's Go menu, hold down the option key, and choose Library
// then browse to the Script Libraries folder
//
// See the section on Library in Apple's JavaScript for Automation Release Notes (10.10 section)
// https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation
//
// PashuaJS.scpt handles the communication with Pashua.app which, for this test should be
// in a system or user Applications folder
// You can either take the handlers out of Pashua.scpt and use them inline whenever you write
// a script which uses Pashua, use PashuaJS.scpt as a JavaScript for Automation Library (OS X 10.10 or newer)
// or use the `var Pashua = Library('PashuaJS')` approach used in this file.
// THIS EXAMPLE USES the Pashua.writeConfig() function to generate Pashua config snippets
// from JavaScript objects or arrays of objects, interleaving these with the Pashua config text.
// Generating Pashua config text at run time may be useful, for example, for populating dialog option lists.
var Pashua = Library('PashuaJS');
var listA = ["alpha", "beta", "gamma"],
listB = ["delta", "epsilon", "zeta"];
var strConfig = '# Set window title \n\
*.title = Welcome to Pashua \n\
\n' + Pashua.writeConfig({ // A single JS object, so the {} need not
// be enclosed in [ array brackets ]
"Comments": "Run-time info",
"name": "inf",
"type": "text",
"default": "Dialog generated from a concatenation of Pashua Config text,\n\n" + new Date().toString() + "\n\nand in-line JavaScript for Automation objects.",
"height": 276,
"width": 310,
"x": 340,
"y": 270,
"tooltip": "This is an element of type “text”"
}) + '\n\
# Introductory text \n\
txt.type = text \n\
txt.default = Pashua is an application for generating dialog windows from programming languages which lack support for creating native GUIs on Mac OS X. Any information you enter in this example window will be returned to the calling script when you hit “OK”; if you decide to click “Cancel” or press “Esc” instead, no values will be returned.[return][return]This window shows nine of the UI element types that are available. You can find a full list of all GUI elements and their corresponding attributes in the documentation (➔ Help menu) that is included with Pashua. \n\
txt.height = 276 \n\
txt.width = 310 \n\
txt.x = 340 \n\
txt.y = 44 \n\
txt.tooltip = This is an element of type “text” \n\
\n\
# Add a text field \n\
tf.type = textfield \n\
tf.label = Example textfield \n\
tf.default = Textfield content \n\
tf.width = 310 \n\
tf.tooltip = This is an element of type “textfield” \n\
\n\
# Add a filesystem browser \n\
ob.type = openbrowser \n\
ob.label = Example filesystem browser (textfield + open panel) \n\
ob.width=310 \n\
ob.tooltip = This is an element of type “openbrowser” \n\
\n' + Pashua.writeConfig([{ // Note that the two JS objects are grouped by [ array brackets ]
"Comments": "Define radiobuttons",
"name": "rb",
"type": "radiobutton",
"label": "Radio buttons from JavaScript array",
"options": listA,
"tooltip": "This is an element of type “radiobutton”"
},
{
"Comments": "Add a popup menu",
"name": "pop",
"type": "popup",
"label": "Popup menu from JavaScript array",
"width": 310,
"options": listB,
"default": listB[0],
"tooltip": "This is an element of type “popup”"
}]) + '\n\
# Add 2 checkboxes \n\
chk.rely = -18 \n\
chk.type = checkbox \n\
chk.label = Pashua offers checkboxes, too \n\
chk.tooltip = This is an element of type “checkbox” \n\
chk.default = 1 \n\
chk2.type = checkbox \n\
chk2.label = But this one is disabled \n\
chk2.disabled = 1 \n\
chk2.tooltip = Another element of type “checkbox” \n\
\n\
# Add a cancel button with default label \n\
cb.type = cancelbutton \n\
cb.tooltip = This is an element of type “cancelbutton” \n\
\n\
db.type = defaultbutton \n\
db.tooltip = This is an element of type “defaultbutton” (which is automatically added to each window, if not included in the configuration) \n\
'
var a = Application.currentApplication(),
sa = (a.includeStandardAdditions = true, a),
// Import ~/Library/Script Libraries/PashuaJS.scpt
Pashua = Library('PashuaJS'),
// Supply a dialog configuration,
// and get results of user interaction
dctResults = Pashua.showDialog(strConfig);
sa.activate();
sa.displayDialog(
'JavaScript for Automation received the following key:value\n' +
'results from a Pashua.app dialog:\n\n' +
JSON.stringify(
dctResults,
null, 2
), {
buttons: ['OK'],
defaultButton: 'OK',
withTitle: 'Pashua binding for JavaScript for Automation'
}
);
dctResults;