# Script variables When calling a shell script or AppleScript from a classic PopClip script action (not from JavaScript), the script receives a set of variables that describe the input text and the context in which the action was triggered. **Note: Variables in JavaScript** In JavaScript, variables are on the [`popclip` global object](https://www.popclip.app/dev/js-environment.md). ## Shell Script variables All values are provided as strings. Where no value is available, it will be set to an empty string. PopClip sets script variables named like this: `POPCLIP_TEXT`, `POPCLIP_BROWSER_TITLE`, `POPCLIP_OPTION_FOO`, etc. ```shell open "https://translate.google.com/?text=${POPCLIP_URLENCODED_TEXT}" ``` ## AppleScript variables Within an AppleScript, PopClip pre-processes the script to replace placeholders with strings. Placeholders look like this: `{popclip text}`, `{popclip browser title}`, `{popclip option foo}`, etc. ```applescript display dialog "{popclip text}" with title "Selected in {popclip app name}" ``` ## Available variables | Shell Script | AppleScript | Description | | ------------------------------ | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `POPCLIP_TEXT` | `{popclip text}` | The part of the selected plain text matching the specified regex or requirement. | | `POPCLIP_FULL_TEXT` | `{popclip full text}` | The selected plain text in its entirety. | | `POPCLIP_HTML` | `{popclip html}` | Sanitized HTML for the selection. CSS is removed, potentially unsafe tags are removed and markup is corrected. (`captureHtml` must be specified.) | | `POPCLIP_URLENCODED_TEXT` | `{popclip urlencoded text}` | URL-encoded form of the matched text. | | `POPCLIP_RAW_HTML` | `{popclip raw html}` | The original unsanitized HTML, if available. (`captureHtml` must be specified.) | | `POPCLIP_MARKDOWN` | `{popclip markdown}` | A conversion of the HTML to Markdown. (`captureHtml` must be specified.) | | `POPCLIP_URLS` | `{popclip urls}` | Newline-separated list of web URLs that PopClip detected in the selected text. | | `POPCLIP_MODIFIER_FLAGS` | `{popclip modifier flags}` | Modifier flags for the keys held down when the extension's button was clicked in PopClip. Values are as defined in [Modifier values](#modifier-values). For example, `0` for no modifiers, or `131072` if shift is held down. | | `POPCLIP_BUNDLE_IDENTIFIER` | `{popclip bundle identifier}` | Bundle identifier of the app the text was selected in. For example, `com.apple.Safari`. | | `POPCLIP_APP_NAME` | `{popclip app name}` | Name of the app the text was selected in. For example, `Safari`. | | `POPCLIP_BROWSER_TITLE` | `{popclip browser title}` | The title of the web page that the text was selected from. (Supported browsers only.) | | `POPCLIP_BROWSER_URL` | `{popclip browser url}` | The URL of the web page that the text was selected from. (Supported browsers only.) | | `POPCLIP_OPTION_*` | `{popclip option *}` | One such value is generated for each option specified in the extension's `options`, where `*` represents the option's `identifier`. For boolean options, the value will be a string, either `0` or `1`. | | `POPCLIP_EXTENSION_IDENTIFIER` | `{popclip extension identifier}` | This extension's identifier. | | `POPCLIP_ACTION_IDENTIFIER` | `{popclip action identifier}` | The identifier specified in the action's configuration, if any. | ## Modifier values This table gives the numeric value for every possible modifier combination. | Keys | Value | | ---- | ------- | | none | 0 | | ⇧ | 131072 | | ⌃ | 262144 | | ⌃⇧ | 393216 | | ⌥ | 524288 | | ⌥⇧ | 655360 | | ⌃⌥ | 786432 | | ⌃⌥⇧ | 917504 | | ⌘ | 1048576 | | ⇧⌘ | 1179648 | | ⌃⌘ | 1310720 | | ⌃⇧⌘ | 1441792 | | ⌥⌘ | 1572864 | | ⌥⇧⌘ | 1703936 | | ⌃⌥⌘ | 1835008 | | ⌃⌥⇧⌘ | 1966080 |