Page 1 of 1
Passing switch variable in script
Posted: Thu Mar 14, 2024 3:23 pm
by rhd_ole
Just start by saying I'm not a scripting expert but trying to keep expanding my knowledge. I'm using python to manipulate some pdfs, excel, csv etc via execute command.
I've only used the %1 and %2 system variables for the input and output but I'd like to pass some Switch privatedata keys to the script but I'm not sure how like I do with javascript. Anyone able to help?
Re: Passing switch variable in script
Posted: Thu Mar 14, 2024 5:10 pm
by magnussandstrom
Re: Passing switch variable in script
Posted: Thu Mar 14, 2024 5:24 pm
by rhd_ole
That sounds like it would work, but really after to to actually write it. I'm going to for sure try this out! Thanks as always.
Re: Passing switch variable in script
Posted: Fri Mar 15, 2024 11:13 am
by rhd_ole
I just figured it out and not sure why I spaced it, so posting for anyone else that is self-teaching.
variables are just passed in the command line in the execute command.
example: "path to your script" %1 %2 [PrivateData:Key="yourvalue"]
and then in the script they are done as:
argv[0] is reserved and shouldn't be used.
file_path = argv[1]
output_path = argv[2]
your variable in the script' = argv[3] since I'm on MacOS I Use sys.argv[]
and so on...
Re: Passing switch variable in script
Posted: Mon Apr 29, 2024 12:07 pm
by gregbowers
To pass Switch private data keys to your Python script using the Execute command, you can utilize command-line arguments.
In your Execute command configuration, you can specify additional parameters after the script path and use them within your Python script. For example, if you have a Switch private data key named 'my_key', you can pass its value as a command-line argument like this:
python my_script.py %1 %2 %my_key%
Within your Python script, you can access this argument using the sys.argv list. Here's an example of how you can retrieve the value of 'my_key' within your script:
import sys
# Retrieve the value of 'my_key' from the command-line arguments
my_key_value = sys.argv[3]
# Now you can use my_key_value in your script as needed
print("Value of 'my_key':", my_key_value)
Replace 'my_script.py' with the path to your Python script and adjust the index in sys.argv[] based on the position of your private data key in the Execute command configuration.
hope it helps