### Get Files with get_files() and Resize Images Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `get_files()` to prompt the user for file selection. The example demonstrates resizing selected images to a specific width while maintaining aspect ratio and saving the result. ```python from shortcutpy.dsl import * @shortcut(name="Resize Images", color="lightblue", glyph="image") def resize_images(): # Prompt user to select files files = get_files() # Process each file for image in files: # Resize to width 1200, maintaining aspect ratio resized = resize_image(image, width=1200) # Prompt user where to save save_file(resized) ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Installs shortcutpy and its development dependencies using pip. ```bash pip install -e .[dev] ``` -------------------------------- ### Dump Installed Shortcut (CLI) Source: https://context7.com/answerdotai/shortcutpy/llms.txt Export an installed shortcut from Shortcuts.app to a text reference format using the `shortcutpy dump` command. Output can be directed to stdout or a file. ```bash # Dump an installed shortcut to stdout shortcutpy dump "My Shortcut Name" ``` ```bash # Dump to a file for reference or parity testing shortcutpy dump "timestamp discord" -O examples/timestamp_discord.original.txt ``` -------------------------------- ### Choose Signing Mode Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Specify the signing mode for compiled shortcuts using the --mode flag. For example, use '--mode anyone' for broader distribution. ```bash shortcutpy path/to/shortcut.py --mode anyone ``` -------------------------------- ### Access Shortcut Input with shortcut_input() Source: https://context7.com/answerdotai/shortcutpy/llms.txt Retrieve input passed to the shortcut via share sheets or other shortcuts using `shortcut_input()`. The example also shows how to get clipboard content as a fallback and extract URLs. ```python from shortcutpy.dsl import * @shortcut(name="Process Input", color="pink", input_types=["text", "url"]) def process_input(): # Get input passed to shortcut shared = shortcut_input() # Get clipboard as fallback clipboard = get_clipboard() # Combine sources for processing source = f"{shared}\n{clipboard}" # Extract URLs from the combined input urls = get_ur_ls(source) show_result(urls) ``` -------------------------------- ### Regenerate Shortcut Reference Dump Source: https://github.com/answerdotai/shortcutpy/blob/main/examples/README.md Use this command to regenerate a text dump of an installed Shortcut. This is helpful for comparing the Python implementation against the actual Shortcut behavior or for backup purposes. ```bash shortcutpy dump "timestamp discord" -O examples/timestamp_discord.original.txt ``` -------------------------------- ### Compile, Sign, and Open Shortcut Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Compiles, signs, and then opens the generated Shortcut file. The file is written to a temporary directory named after the shortcut's output name. ```bash shortcutpy -o path/to/file.py ``` -------------------------------- ### Present Menu Options with choose_from_menu() Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `choose_from_menu` to display a list of options to the user and capture their selection. Ensure options are provided as a list of strings. ```python from shortcutpy.dsl import * @shortcut(name="Menu Selection", color="purple") def menu_demo(): # Define menu options as a list options = ["Option A", "Option B", "Option C"] # Prompt user to choose choice = choose_from_menu("Select an option:", options) show_result(f"You selected: {choice}") ``` -------------------------------- ### Compile Shortcut from File Path with Options Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `compile_file()` to compile a shortcut from a file path, with options for output location, signing, and signing modes. Catch `CompileError` for detailed error reporting. ```python from shortcutpy import compile_file, CompileError from pathlib import Path try: # Compile with default options (signed, outputs next to source) artifact = compile_file("examples/hello_world.py") # Compile with custom output path artifact = compile_file( "examples/hello_world.py", output="/tmp/my_shortcut.shortcut" ) # Compile without signing artifact = compile_file( "examples/hello_world.py", sign=False ) # Compile with specific signing mode artifact = compile_file( "examples/hello_world.py", mode="anyone", # or "people-who-know-me" keep_unsigned=True # Keep intermediate unsigned file ) except CompileError as e: print(f"Compilation failed at {e.filename}:{e.node.lineno}: {e.message}") ``` -------------------------------- ### Run Tests Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Executes the test suite for shortcutpy with quiet output. ```bash pytest -q ``` -------------------------------- ### Compile, Sign, and Open Shortcut Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Compile and sign a shortcut, then automatically open the resulting .shortcut file in the macOS Shortcuts application. This process uses a temporary directory for building. ```bash shortcutpy -o path/to/shortcut.py ``` -------------------------------- ### Compile and Sign Python to Shortcut Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Compiles a Python file into a Shortcut payload and signs it using the default signing process. ```bash shortcutpy path/to/file.py ``` -------------------------------- ### Check Code Style Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Runs the chkstyle linter on the shortcutpy project and tests. ```bash chkstyle shortcutpy tests ``` -------------------------------- ### Compile and Sign a Shortcut Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Compile a Python shortcut script into a .shortcut file and sign it using the shortcutpy command-line tool. By default, the output file is placed next to the source file. ```bash shortcutpy path/to/shortcut.py ``` -------------------------------- ### Compile and Write Shortcut to Specific Path Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Compile and sign a shortcut, specifying an exact output path for the .shortcut file. This overrides the default behavior of placing the file next to the source. ```bash shortcutpy -O /tmp/my.shortcut path/to/shortcut.py ``` -------------------------------- ### Compile Python to Shortcut (CLI) Source: https://context7.com/answerdotai/shortcutpy/llms.txt Compile Python source files into signed Apple Shortcut files using the `shortcutpy` CLI. Options include skipping signing, immediate opening, specifying output paths, keeping intermediate files, and different signing modes. ```bash # Basic compilation - writes "Hello, shortcutpy!.shortcut" next to source shortcutpy examples/hello_world.py ``` ```bash # Compile without signing (for debugging or inspection) shortcutpy examples/hello_world.py --skip-sign ``` ```bash # Compile and immediately open in Shortcuts.app shortcutpy -o examples/hello_world.py ``` ```bash # Write output to a specific path shortcutpy -O /tmp/my_shortcut.shortcut examples/hello_world.py ``` ```bash # Keep the intermediate unsigned file (useful for debugging) shortcutpy examples/hello_world.py --keep-unsigned ``` ```bash # Use a different signing mode shortcutpy examples/hello_world.py --mode anyone ``` -------------------------------- ### Use Generated Typed Action Wrappers Source: https://context7.com/answerdotai/shortcutpy/llms.txt Access over 300 Shortcuts actions as typed Python functions for common tasks like weather, notifications, text manipulation, and HTTP requests. Ensure necessary imports from `shortcutpy.dsl`. ```python from shortcutpy.dsl import * # Weather @shortcut(name="Current Weather", color="blue") def weather_demo(): weather = get_current_weather() show_result(weather) ``` ```python from shortcutpy.dsl import * # Notifications @shortcut(name="Notify Demo", color="red") def notify_demo(): show_notification("Task completed!", title="Success", play_sound=True) ``` ```python from shortcutpy.dsl import * # Date/Time formatting @shortcut(name="Format Demo", color="green") def format_demo(): now = current_date() formatted = format_timestamp(now, date_format="Long", time_format="Short") weekday = format_timestamp(now, custom_date_format="EEEE") show_result(f"{weekday}, {formatted}") ``` ```python from shortcutpy.dsl import * # Text manipulation @shortcut(name="Text Demo", color="purple") def text_demo(): input_text = ask_for_text("Enter text:") upper = uppercase(input_text) replaced = replace_text("old", "new", input_text) show_result(f"Uppercase: {upper}") ``` ```python from shortcutpy.dsl import * # Clipboard operations @shortcut(name="Clipboard Demo", color="gray") def clipboard_demo(): text = ask_for_text("Text to copy:") set_clipboard(text) show_notification("Copied to clipboard!") ``` ```python from shortcutpy.dsl import * # HTTP requests @shortcut(name="HTTP Demo", color="darkblue") def http_demo(): response = download_url("https://api.example.com/data") dict_data = get_dictionary(response) value = dict_data["key"] show_result(value) ``` ```python from shortcutpy.dsl import * # Regular expressions @shortcut(name="Regex Demo", color="orange") def regex_demo(): text = ask_for_text("Enter text:") matches = match_text("\\d+", text) show_result(matches) ``` -------------------------------- ### Create and Use Lists and Dictionaries Source: https://context7.com/answerdotai/shortcutpy/llms.txt ShortcutPy compiles Python list and dictionary literals into native Shortcuts List and Dictionary actions. Access elements using index for lists and keys for dictionaries. ```python from shortcutpy.dsl import * @shortcut(name="Data Structures", color="teal") def data_demo(): # List literal becomes a Shortcuts List action fruits = ["apple", "banana", "cherry"] # Access by index (0-based in Python, converted to 1-based for Shortcuts) first = fruits[0] show_result(f"First fruit: {first}") # Dictionary literal becomes a Shortcuts Dictionary action translations = { "hello": "hola", "goodbye": "adios", "thanks": "gracias" } # Lookup by key word = translations["hello"] show_result(f"Hello in Spanish: {word}") # Variable key lookup key = ask_for_text("Enter word to translate:") result = translations[key] show_result(result) ``` -------------------------------- ### Release Flow Commands Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Execute these commands as part of the release flow. Ensure issues are labeled appropriately before running. ```bash ship-gh ``` ```bash ship-pypi ``` -------------------------------- ### Display Results with show_result() Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `show_result` to display information to the user within the Shortcuts output. It can display simple text or formatted strings including variables. ```python from shortcutpy.dsl import * @shortcut(name="Show Result Demo", color="yellow", glyph="smileyFace") def show_demo(): # Display simple text show_result("Hello, shortcutpy!") # Display formatted text with variables name = ask_for_text("Your name?") show_result(f"Welcome, {name}!") ``` -------------------------------- ### Compile Unsigned Shortcut Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Compile a shortcut script without signing it. Use the --skip-sign flag to generate an unsigned .shortcut file. ```bash shortcutpy path/to/shortcut.py --skip-sign ``` -------------------------------- ### Call Raw Shortcuts Actions with Parameters Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `raw_action()` to call any Shortcuts action directly by its identifier with custom parameters. This is useful for actions without typed wrappers or when fine-grained control is needed. ```python from shortcutpy.dsl import * @shortcut(name="Raw Action Alert", color="orange", glyph="alert") def raw_alert(): name = ask_for_text("Who should we greet?") # Call the alert action directly with raw parameters raw_action( "alert", # Action identifier WFAlertActionTitle="shortcutpy", WFAlertActionMessage=f"Hello {name}!" ) ``` ```python from shortcutpy.dsl import * @shortcut(name="Custom HTTP Request", color="blue") def custom_request(): # Use raw_action for complex configurations raw_action( "is.workflow.actions.downloadurl", WFURL="https://api.example.com/data", WFHTTPMethod="GET" ) ``` -------------------------------- ### Compile and Sign ShortcutPy Script Source: https://github.com/answerdotai/shortcutpy/blob/main/examples/README.md This command compiles a Python script into a Shortcut and signs it. Signing is typically required for distribution or when the Shortcut needs to interact with certain system features. ```bash shortcutpy examples/hello_world.py ``` -------------------------------- ### Prompt for Date and Time Input with ask_for_datetime() Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `ask_for_datetime()` to prompt the user to select a date and time. An optional default value, such as the current date, can be specified. ```python from shortcutpy.dsl import * @shortcut(name="DateTime Input", color="orange") def datetime_input(): now = current_date() # Prompt with the current date as default selected = ask_for_datetime("Pick a date:", default=now) # Format and display the selected date formatted = format_timestamp(selected, date_format="Long", time_format="Short") show_result(formatted) ``` -------------------------------- ### Compile Shortcut Source Code Programmatically Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `compile_source()` to compile shortcut source code directly in memory without writing to disk. Handle potential `CompileError` exceptions. ```python from shortcutpy import compile_source, CompileError source = ''' from shortcutpy.dsl import * @shortcut(name="Programmatic", color="green") def main(): show_result("Compiled programmatically!") ''' try: artifact = compile_source(source, filename="example.py") # Access the compiled payload (dict ready for plist serialization) payload = artifact.payload # Access program metadata program = artifact.program print(f"Shortcut name: {program.meta.name}") print(f"Action count: {len(payload['WFWorkflowActions'])}") except CompileError as e: print(f"Compilation failed: {e}") ``` -------------------------------- ### Define a Shortcut with DSL Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md Use the @shortcut decorator to define a shortcut function. Configure shortcut properties like color and glyph. The function body uses DSL functions to interact with the user and display results. ```python from shortcutpy.dsl import shortcut, ask_for_text, choose_from_menu, show_result @shortcut(color="yellow", glyph="hand") def greeting(): name = ask_for_text("What is your name?") tone = choose_from_menu("Tone", ["formal", "casual"]) if tone == "formal": message = f"Good day, {name}." else: message = f"Hey {name}!" show_result(message) ``` -------------------------------- ### Compile ShortcutPy Script Without Signing Source: https://github.com/answerdotai/shortcutpy/blob/main/examples/README.md Use this command to compile a Python script into a Shortcut without code signing. This is useful for quick testing or when signing is not required. ```bash shortcutpy examples/hello_world.py --skip-sign ``` -------------------------------- ### Define Fully Customized Shortcut with @shortcut Source: https://context7.com/answerdotai/shortcutpy/llms.txt Customize shortcut metadata like name, color, glyph, and accepted input types using optional parameters of the `@shortcut` decorator. ```python @shortcut( name="My Custom Shortcut", color="blue", # Shortcuts icon color glyph="hand", # Shortcuts icon glyph input_types=["text", "date"] # Accepted input content types ) def my_shortcut(): data = shortcut_input() show_result(f"Received: {data}") ``` -------------------------------- ### Prompt for Text Input with ask_for_text() Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `ask_for_text()` to prompt the user for text input within a shortcut. An optional default value can be provided. ```python from shortcutpy.dsl import * @shortcut(name="Text Input Demo", color="green") def text_input(): # Simple text prompt name = ask_for_text("What is your name?") # With a default value greeting = ask_for_text("Enter greeting:", default="Hello") show_result(f"{greeting}, {name}!") ``` -------------------------------- ### Keep Intermediate Unsigned File During Signing Source: https://github.com/answerdotai/shortcutpy/blob/main/README.md When signing a shortcut, use the --keep-unsigned flag to retain the intermediate unsigned .shortcut file after the signing process is complete. ```bash shortcutpy path/to/shortcut.py --keep-unsigned ``` -------------------------------- ### Implement Loops with for Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use `for` loops to iterate over lists or repeat actions a specific number of times. Supports 'Repeat with Each' for list iteration and 'Repeat n times' for fixed counts. ```python from shortcutpy.dsl import * @shortcut(name="Loop Demo", color="blue", glyph="textBubble") def loop_examples(): # Iterate over a list (Repeat with Each) people = ["Ada", "Grace", "Linus"] for person in people: show_result(f"Hello {person}") # Fixed count loop (Repeat n times) for i in range(3): show_result(f"Round {i}") ``` -------------------------------- ### Implement Conditional Logic with if/else Source: https://context7.com/answerdotai/shortcutpy/llms.txt Utilize Python's `if/else` statements for conditional execution. Supports standard comparison operators and boolean checks. Nested conditionals are also supported. ```python from shortcutpy.dsl import * @shortcut def coffee_or_tea(): drink = ask_for_text("Coffee or tea?") if drink == "coffee": show_result("Grinding beans") else: show_result("Boiling the kettle") ``` ```python from shortcutpy.dsl import * @shortcut(name="Number Comparison", color="blue") def compare_numbers(): dates = get_dates(shortcut_input()) # Numeric comparison if count(dates) > 0: show_result("Found dates in input") else: show_result("No dates found") ``` -------------------------------- ### Define Minimal Shortcut with @shortcut Source: https://context7.com/answerdotai/shortcutpy/llms.txt Use the `@shortcut` decorator to mark a Python function as the entry point for an Apple Shortcut. When used without arguments, the shortcut name is derived from the function name. ```python from shortcutpy.dsl import * # Minimal shortcut - name becomes "Hello World" from function name @shortcut def hello_world(): show_result("Hello, World!") ``` -------------------------------- ### Discord Timestamp Generator Shortcut Source: https://context7.com/answerdotai/shortcutpy/llms.txt This shortcut generates a Discord timestamp code and copies it to the clipboard. It allows users to select a date and time, then choose a formatting style (long date/time, short date/time, or relative time). The shortcut attempts to use input or clipboard content for the date, falling back to the current date if none is found. ```python from shortcutpy.dsl import * @shortcut(color="pink", glyph="chatBubble", input_types=["text", "date"]) def timestamp_discord(): comment("Generate a Discord timestamp code and copy it to the clipboard.") # Localization dictionary text = { "select-date-time": "Select the date and time for your code", "select-style": "Select a style for your code", "long-date-time-name": "Long date and time", "short-date-time-name": "Short date and time", "long-date-name": "Long date", "short-date-name": "Short date", "long-time-name": "Long time", "short-time-name": "Short time", "relative-time-name": "Relative time", "copied-to-clipboard": "%s copied to clipboard", } # Try to extract date from input or clipboard, fallback to current time shared = shortcut_input() clipboard = get_clipboard() now = current_date() source = f"{shared}\n{clipboard}\n{now}" dates = get_dates(source) selected = now if count(dates) > 0: selected = dates[0] # Let user pick or confirm the date picked = ask_for_datetime(text["select-date-time"], default=selected) # Format date previews for the menu weekday = format_timestamp(picked, custom_date_format="EEEE") long_date = format_timestamp(picked, date_format="Long") short_time = format_timestamp(picked, time_format="Short") # Build menu options with previews options = [ f"Long date and time {weekday}, {long_date} {short_time}", f"Short date and time {long_date} {short_time}", f"Relative time {format_timestamp(picked, date_format='Relative')}" ] style = choose_from_menu(text["select-style"], options) # Map selection to Discord format codes style_codes = { options[0]: "F", options[1]: "f", options[2]: "R" } code = style_codes[style] # Generate and copy the Discord timestamp ts = unix_timestamp(picked) discord_code = f"" set_clipboard(discord_code) show_notification( replace_text("%s", discord_code, text["copied-to-clipboard"]), play_sound=False ) ``` -------------------------------- ### Bump Version Number Source: https://github.com/answerdotai/shortcutpy/blob/main/DEV.md Use the ship-bump command to increment the version number. Specify --part 2 for patch, --part 1 for minor, and --part 0 for major releases. ```bash ship-bump --part 2 # patch ``` ```bash ship-bump --part 1 # minor ``` ```bash ship-bump --part 0 # major ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.