rdhyee / py-applescript

An easy-to-use Python wrapper for NSAppleScript, allowing Python scripts to communicate with AppleScripts and AppleScriptable applications.
Creative Commons Zero v1.0 Universal
140 stars 7 forks source link

Possible to call script with arguments AND as a separate file? #13

Closed Scott-Larsen closed 2 years ago

Scott-Larsen commented 2 years ago

I'm trying to call a separate Applescript file as well as pass it a series of ~8 arguments. I can do one or the other but I'm not sure how one would do both and, as a junior developer, I can't quite make out how the code works inside. I'm imagining it'd be something like this. Any help is appreciated.

import applescript

clientName = "Wonderful Client"
applescript.AppleScript(path="automation.scpt").run(clientName)

Here's an example of the arguments I'm trying to pass - they're mostly just strings and lists so I don't think the problem is there. arguments

Scott-Larsen commented 2 years ago

I was able to get it working with the following.

import applescript

APPLESCRIPT_LOCATION = "software_automation.scpt"

INPUT_LIST = ["/Users/User1/Downloads/input1"]
OUTPUT_LIST = [
    "/Users/User1/Downloads/output1",
    "/Users/User1/Downloads/output2",
    "/Users/User1/Downloads/output3",
]

CLIENT_NAME = "Client Name1"
PROJECT_NAME = "Project Name1"
JOB_NAME = "Job Name1"

EMAIL_ADDRESSES = "user@example.com"
REPORTS_DESTINATION = "/Users/User1/Downloads/1"

def software_automation(
    input_list,
    output_list,
    client_name,
    project_name,
    job_name,
    email_addresses,
    reports_destination,
):
    applescript.AppleScript(path=APPLESCRIPT_LOCATION).run(
        input_list,
        output_list,
        client_name,
        project_name,
        job_name,
        email_addresses,
        reports_destination,
    )

software_automation(
    input_list=INPUT_LIST,
    output_list=OUTPUT_LIST,
    client_name=CLIENT_NAME,
    project_name=PROJECT_NAME,
    job_name=JOB_NAME,
    email_addresses=EMAIL_ADDRESSES,
    reports_destination=REPORTS_DESTINATION,
)
rdhyee commented 2 years ago

@Scott-Larsen I'm glad that you got things working.