├── .gitignore ├── Example.applescript ├── Pashua.applescript ├── Readme.md └── compile.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /Pashua.scpt 2 | /Example.scpt 3 | 4 | -------------------------------------------------------------------------------- /Example.applescript: -------------------------------------------------------------------------------- 1 | 2 | -- This example loads script "Pashua.scpt" (to be compiled from "Pashua.applescript") from the 3 | -- same folder which contains this file. Pashua.scpt handles the communication with Pashua.app. 4 | -- You can either take the handlers out of Pashua.scpt and use them inline whenever you write 5 | -- a script which uses Pashua, use Pashua.scpt as an AppleScript Library (OS X 10.9 or newer) 6 | -- or use the "load script" approach used in this file. 7 | 8 | 9 | -- Get the path to the folder containing this script 10 | tell application "Finder" 11 | set thisFolder to (container of (path to me)) as string 12 | if "Pashua:Pashua.app:" exists then 13 | -- Looks like the Pashua disk image is mounted. Run from there. 14 | set customLocation to "Pashua:" 15 | else 16 | -- Search for Pashua in the standard locations 17 | set customLocation to "" 18 | end if 19 | end tell 20 | 21 | try 22 | set thePath to alias (thisFolder & "Pashua.scpt") 23 | set pashuaBinding to load script thePath 24 | 25 | tell pashuaBinding 26 | -- Display the dialog 27 | 28 | try 29 | set pashuaLocation to getPashuaPath(customLocation) 30 | set dialogConfiguration to my getDialogConfiguration(pashuaLocation) 31 | set theResult to showDialog(dialogConfiguration, customLocation) 32 | 33 | -- Display the result. The record keys ("... of theResult") are defined in the 34 | -- dialog configuration string. 35 | if {} = theResult then 36 | display alert "Empty return value" message "It looks like Pashua had some problems using the window configuration." as warning 37 | else if cb of theResult is not "1" then 38 | display dialog "AppleScript received this record: " & return & return & ¬ 39 | "pop: " & pop of theResult & return & ¬ 40 | "ob: " & ob of theResult & return & ¬ 41 | "tf: " & tf of theResult & return & ¬ 42 | "chk: " & chk of theResult & return & ¬ 43 | "rb: " & rb of theResult & return 44 | else 45 | -- The cancelbutton (named "cb" in the config string) was pressed 46 | display dialog "The dialog was closed without submitting the values" 47 | end if 48 | on error errorMessage 49 | display alert "An error occurred" message errorMessage as warning 50 | end try 51 | end tell 52 | 53 | on error errStr number errorNumber 54 | display dialog errStr 55 | end try 56 | 57 | 58 | -- Returns the configuration string for an example dialog 59 | on getDialogConfiguration(pashuaLocation) 60 | 61 | if pashuaLocation is not "" then 62 | set img to "img.type = image 63 | img.x = 435 64 | img.y = 248 65 | img.maxwidth = 128 66 | img.tooltip = This is an element of type “image” 67 | img.path = " & (POSIX path of pashuaLocation) & "/Contents/Resources/AppIcon@2.png" & return 68 | else 69 | set img to "" 70 | end if 71 | 72 | return " 73 | # Set window title 74 | *.title = Welcome to Pashua 75 | 76 | # Introductory text 77 | txt.type = text 78 | 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. 79 | txt.height = 276 80 | txt.width = 310 81 | txt.x = 340 82 | txt.y = 44 83 | txt.tooltip = This is an element of type “text” 84 | 85 | # Add a text field 86 | tf.type = textfield 87 | tf.label = Example textfield 88 | tf.default = Textfield content 89 | tf.width = 310 90 | tf.tooltip = This is an element of type “textfield” 91 | 92 | # Add a filesystem browser 93 | ob.type = openbrowser 94 | ob.label = Example filesystem browser (textfield + open panel) 95 | ob.width=310 96 | ob.tooltip = This is an element of type “openbrowser” 97 | 98 | # Define radiobuttons 99 | rb.type = radiobutton 100 | rb.label = Example radiobuttons 101 | rb.option = Radiobutton item #1 102 | rb.option = Radiobutton item #2 103 | rb.option = Radiobutton item #3 104 | rb.tooltip = This is an element of type “radiobutton” 105 | 106 | # Add a popup menu 107 | pop.type = popup 108 | pop.label = Example popup menu 109 | pop.width = 310 110 | pop.option = Popup menu item #1 111 | pop.option = Popup menu item #2 112 | pop.option = Popup menu item #3 113 | pop.default = Popup menu item #2 114 | pop.tooltip = This is an element of type “popup” 115 | 116 | # Add 2 checkboxes 117 | chk.rely = -18 118 | chk.type = checkbox 119 | chk.label = Pashua offers checkboxes, too 120 | chk.tooltip = This is an element of type “checkbox” 121 | chk.default = 1 122 | chk2.type = checkbox 123 | chk2.label = But this one is disabled 124 | chk2.disabled = 1 125 | chk2.tooltip = Another element of type “checkbox” 126 | 127 | # Add a cancel button with default label 128 | cb.type = cancelbutton 129 | cb.tooltip = This is an element of type “cancelbutton” 130 | 131 | db.type = defaultbutton 132 | db.tooltip = This is an element of type “defaultbutton” (which is automatically added to each window, if not included in the configuration) 133 | " & img 134 | end getDialogConfiguration 135 | -------------------------------------------------------------------------------- /Pashua.applescript: -------------------------------------------------------------------------------- 1 | -- Pashua binding for AppleScript. 2 | -- See Readme.md for authors/contributors and license 3 | 4 | -- Usage: either take the handlers out of this file and use them directly, 5 | -- use this file as an AppleScript Library (OS X 10.9 or newer) or 6 | -- follow the "classical" approach using "load script". The example 7 | -- script shipped with this file uses "load script" for maximum 8 | -- compatibility. 9 | 10 | -- Runs a Pashua dialog and returns the results as a list 11 | -- 12 | -- Argument 1: Dialog/window configuration string 13 | -- Argument 2: Folder that contains Pashua.app; if an empty string is given, default locations are searched 14 | -- 15 | -- Returns: Record 16 | on showDialog(config, customLocation) 17 | 18 | -- Create path for temporary file 19 | set AppleScript's text item delimiters to "" 20 | set tmpfile to ((path to temporary items folder as string) & "Pashua_" & (characters 3 thru end of ((random number) as string)) as string) 21 | 22 | -- Write temporary file and fill it with the configuration string 23 | set fhandle to open for access tmpfile with write permission 24 | write (config as string) to fhandle as «class utf8» 25 | close access fhandle 26 | 27 | -- Get temporary file's POSIX path 28 | set posixtmpfile to POSIX path of tmpfile 29 | 30 | -- try 31 | set pashua to getPashuaPath(customLocation) 32 | -- on error errorMessage 33 | -- display dialog errorMessage 34 | -- end try 35 | 36 | -- Append binary position inside app bundle to "regular" path 37 | -- and convert path from HFS to POSIX representation 38 | set pashuabinary to (POSIX path of pashua) & "Contents/MacOS/Pashua" 39 | 40 | -- Execute pashua and get the string returned 41 | set pashuaCall to quoted form of pashuabinary & " " & quoted form of posixtmpfile 42 | set pashuaResult to do shell script (pashuaCall) 43 | 44 | -- Delete the temporary file 45 | tell application "System Events" to delete file tmpfile -- silently and immediately delete the tempfile 46 | 47 | -- Check whether the dialog was submitted at all. 48 | -- If this is not the case, return an empty list 49 | if pashuaResult = "" then 50 | return {} 51 | end if 52 | 53 | -- Parse the result 54 | set AppleScript's text item delimiters to return 55 | set resultLines to text items of pashuaResult 56 | set AppleScript's text item delimiters to "" 57 | set recordComponents to {} 58 | repeat with currentLine in resultLines 59 | set eqpos to offset of "=" in currentLine 60 | if eqpos is not 0 then 61 | set varKey to word 1 of currentLine 62 | try 63 | set varValue to (text (eqpos + 1) thru end of currentLine) 64 | -- Quote any quotation marks in varValue with a backslash. 65 | -- The proper way to do this would be a handler, but as 66 | -- all code for interfacing to Pashua should be as compact 67 | -- as possible, we rather do it inline 68 | set AppleScript's text item delimiters to "\"" 69 | set textItems to every text item of varValue 70 | set AppleScript's text item delimiters to "\\\"" 71 | set varValue to textItems as string 72 | set AppleScript's text item delimiters to "" 73 | on error 74 | set varValue to "" 75 | end try 76 | copy (varKey & ":\"" & varValue & "\"") to end of recordComponents 77 | end if 78 | end repeat 79 | 80 | -- Return the record we read from the tmpfile 81 | set AppleScript's text item delimiters to ", " 82 | set resultList to (run script "return {" & (recordComponents as string) & "}") 83 | set AppleScript's text item delimiters to {""} 84 | return resultList 85 | 86 | end showDialog 87 | 88 | 89 | -- Searches Pashua.app in the location given as argument and in standard search paths 90 | -- 91 | -- Will trigger an error if Pashua.app cannot be found 92 | -- 93 | -- Argument: Folder that contains Pashua.app; if an empty string is given, default locations are searched 94 | -- 95 | -- Returns: string 96 | on getPashuaPath(customFolder) 97 | 98 | set myself to (path to me as string) 99 | 100 | -- Try to find Pashua application 101 | tell application "Finder" 102 | 103 | -- Custom location 104 | if customFolder is not "" then 105 | if last character of customFolder = ":" then 106 | set dirsep to "" 107 | else 108 | set dirsep to ":" 109 | end if 110 | if item (customFolder & dirsep & "Pashua.app") exists then 111 | return customFolder & dirsep & "Pashua.app:" 112 | end if 113 | end if 114 | 115 | -- Try to find it in this script application bundle 116 | if item (myself & "Contents:MacOS:Pashua") exists then 117 | return myself 118 | end if 119 | 120 | -- Try to find it in this script's parent's path 121 | set myFolder to (container of alias myself as string) 122 | if item (myFolder & "Pashua.app") exists then 123 | return (myFolder & "Pashua.app:") 124 | end if 125 | 126 | -- Try to find it in global application folder 127 | if item ((path to applications folder from system domain as text) & "Pashua.app") exists then 128 | return (path to applications folder from system domain as text) & "Pashua.app:" 129 | end if 130 | 131 | -- Try to find it in user's application folder 132 | if item ((path to applications folder from user domain as text) & "Pashua.app") exists then 133 | return ((path to applications folder from user domain as text) & "Pashua.app:") 134 | end if 135 | 136 | error "Could not find Pashua.app" & return & return & "It looks like it is neither in one of the standard locations nor in the folder this AppleScript is in." 137 | 138 | end tell 139 | 140 | end getPashuaPath 141 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Overview 2 | =========== 3 | This is an AppleSript language binding (glue code) for using Pashua with AppleScript. Pashua is a macOS application for using native GUI dialog windows in various programming languages. 4 | 5 | This code can be found in a GitHub repository at https://github.com/BlueM/Pashua-Binding-AppleScript. For examples in other programming languages, see https://github.com/BlueM/Pashua-Bindings. 6 | 7 | Other related links: 8 | * [Pashua homepage](https://www.bluem.net/jump/pashua) 9 | * [Pashua repository on GitHub](https://github.com/BlueM/Pashua) 10 | 11 | Usage 12 | ====== 13 | This repository contains uncompiled AppleScript code. You can open “Example.applescript” and run it in the script editor, but it needs a compiled version of “Pashua.applescript” (which is also in this folder). 14 | 15 | Solution: simply open a Terminal window, run “compile.sh” (i.e.: drag the icon onto the Terminal window and hit Return) and you’re done. You will now have “Example.scpt” and “Pashua.scpt”. “Example.scpt” is the actual example, and “Pashua.scpt” is the “library” for handling the communication with Pashua. 16 | 17 | Of course, you will need Pashua on your Mac to run the example. The code expects Pashua.app in one of the “typical” locations, such as the global or the user’s “Applications” folder, or in the folder which contains “Example.scpt” and 18 | “Pashua.scpt”. 19 | 20 | 21 | Compatibility 22 | ============= 23 | This code should run at least on Mac OS X 10.6 or later. 24 | 25 | It is compatible with Pashua 0.10. It will work with earlier versions of Pashua, but non-ASCII characters will not be displayed correctly, as any versions before 0.10 required an argument for marking input as UTF-8. If you want to use this code with Pashua < 0.10, you can remove partial line `as «class utf8»` in “Pashua.applescript” or “Pashua.scpt” respectively. 26 | 27 | 28 | Authors 29 | ========= 30 | This code was written by Carsten Blüm, contributions by Eddy Roosnek and Hans Haesler. 31 | 32 | 33 | License 34 | ========= 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in all 43 | copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 51 | SOFTWARE. 52 | 53 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | osacompile -o "$DIR/Pashua.scpt" "$DIR/Pashua.applescript" 5 | osacompile -o "$DIR/Example.scpt" "$DIR/Example.applescript" 6 | --------------------------------------------------------------------------------