Posted on 03-08-2017 07:03 AM
Hi all. I've been working on a script that is used in self service which allows users to enter a tag number for a printer and then the printer is mapped. The script pulls from a CSV file. We have been able to make this work for all non-MFD machines and MFD machines separately. Unfortunately I cannot manage to get a combined script that will do both.
The reason this is occurring is that no matter what it always goes to the very last conditional statement, in most cases the else, even if the statement is true.
In these screen shots, you can see the script and what happens when I run (I excluded the prompt asking for the user input tag, but included showing the tag entered and showing that Canon is the manufacturer. I never receive the pop up, as I should since the if [ "$Manu" = "Canon" ] statement is true. I've tried many different combinations of syntax for this if/nested if/loop statement, and all results have it ignoring and going right to the final conditional. Any help would be great.
Solved! Go to Solution.
Posted on 03-08-2017 08:03 AM
I solved this myself fortunately. I made some changes to the conditionals, removing quotes and also using a wildcard to see if it was like "anon" essentially in place of Canon. I also added in the other statements below as a test so it works for both MFD and non MFD machines now.
Posted on 03-08-2017 07:07 AM
Posted on 03-08-2017 07:53 AM
Try exporting the variables returned from the spreadsheet as they probably are not being passed to the Applescript
Posted on 03-08-2017 08:03 AM
I solved this myself fortunately. I made some changes to the conditionals, removing quotes and also using a wildcard to see if it was like "anon" essentially in place of Canon. I also added in the other statements below as a test so it works for both MFD and non MFD machines now.
Posted on 03-08-2017 09:01 AM
I've had this previously crossing into another language within the script, you have to export the variables.
#!/bin/sh
# Set start script runtime
startTime=$(date +%s)
sleep 30s
# Calculate script run time and display
finishTime=$(date +%s)
totalTime=$((finishTime - startTime))
export totalTime
# Applescript to display completed message
osascript -e 'display notification "Completed in '$totalTime' secs. with title "Script Timer"'
Posted on 03-08-2017 11:46 AM
Hi guys -
Actually, a shell script or the shell will pass a bash variable to the osascript command without need for exporting. Also, in the osascript example above, there is a missing quote. Your command should look like this:
osascript -e 'display notification "Completed in '$totalTime' secs." with title "Script Timer"'
Your example is missing a double quote after the word "secs."
1 last thing: this is an odd example (as are most AppleScript snippets) of quoting. In most scripting languages single quotes enable literal strings, meaning, characters in between single quotes are interpreted as characters & special characters don't have their normal functions. In bash, this would mean that something like:
'$totalTime'
would not undergo variable expansion but would literally just print $totalTime. As you can see in AppleScript this is not the case, so, be careful. Happy Scripting!