Run applescript in Automator Workflow to run only if the comp name

I need some help.

Here is my situation. I use iCal to schedule an Automator Workflow to run. I only need this workflow to run on my work computer and not my other personal computers. I have .Mac and the iCal’s sync so regardless of computer, the work flow tries to run on all of them at a certain time if they are on.

I figure the easiest way, and possibly the only way to do this in Automator, is to have an apple script run and test the name of the computer against the computer name I want it to run on. If they match, set the input variable to a value and have the next step in the workflow “Stop if Input is Empty” action. This way if the computer names match, the workflow will run but if they don’t match the workflow will stop and not run on other machines.

I have this is my workflow

on run {input, parameters}

if (do shell script "hostname") = "iMac-24.local" then
	input = "1"
end if

return input

end run


then the Stop if Input is empty action but I can’t get this to work. When I run the shell script above on the computer I am on, it matches the iMac-24.local description since I am testing it on this computer. It should work.

Check out the Automator Screen shot here. http://www.installuniversity.com/images/Picture 2.png

Can you offer any help?

TIA!

HI Dude

You could look into setting up something via launchd to schedule a script or automator action.
Try looking into an app called lingon to help you with the timing.
good luck

Thank you very much for the advice on the program. I am going to use it for a different reason.

However, I still want to get this working in Automator so I can update or change the time on any computer anywhere in the world and have .Mac make the change without having to VNC into the machine.

Any thoughts on the Apple Script code for this? I imagine it is really easy but I am missing something.

You could try something like this

set Cname to do shell script "hostname"
if Cname is equal to "iMac-24.local" then
	beep
else
	display dialog "You do not have permission to use this script" with icon stop giving up after 3
end if

Hi Dude

This is same as darock just all applescript:

set x to (get system info)
if host name of x = "iMac-24.local" then
	display dialog "yes"
else
	display dialog "No"
end if

Thanks guys! However, I can get dialouge boxes to appear. However, I am needing a litmus test if you will, that determines automatically if the computer name matches up to know whether or not to run on that computer.

For some reason, I can set the variable in the apple script to be “1” if a computer name match is found but Automator does not recognize this as valid “Input” for the next action (which is "Stop If Input Is Empty). Obviously, if the names match, then “Input” should be “1” and the “input” variable is not empty. But yet the script stops there anyway.

Any thoughts?

I replied to your other thread.

sorry dude! the point of the dialog boxes was just to show a desired result. true if it meets a certain criteria (i.e. whether the host name exists on that machine) and false if not.

system info

run this and check the result
you should be able to get the name of various elements of your machine from this.
which you can use in your script to determine various naming conditions etc…

i think you may need to be setting your variable to “1” not just variable =“1”
i did try this in automator and its quite difficult to get it to return nothing
eventually came up with this and the automator action stops where you want.
not sure if this is what your after, you’ll have to give it a go.
think you need to lose the on run {input,parmeters}-end run bit

tell (system info) to set x to host name of it
if x = "iMac-24.local" then
	set x to 1
else
	some item
end if

We have the problem solved. I can return a 1 if the computer name matches. This needs to be passed to the next Automator action “Stop if Input is Empty.”
This is where the problem lies. The automator actions are not working like they should or I am not storing the input in the correct variable for the next action.

In the first script you posted, your code was this:

if (do shell script “hostname”) = “iMac-24.local” then
input = “1”
end if

In this case, I think you aren’t setting the input correctly. input = “1” is boolean and resolves to “false” without changing the input variable.

Try

if (do shell script “hostname”) = “iMac-24.local” then
set input to 1
end if

Vince

Your suggestion worked. Thanks! You were correct.

Automator is a bit of pain at times and this is one of them.

Here is my workflow snapshot. http://www.installuniversity.com/images/Picture 3.png

When I run the workflow I get this window http://www.installuniversity.com/images/Picture 4.png
I have to hit the continue button for it to continue to run. Once I hit continue it runs perfect. Any idea how to get Automator to keep running without the continue button? Surely to goodness it doesn’t act this way with every Applescript snipet put in a workflow?

TIA People! I really appreciate!!

That’s unusual. Click on the options triangle on the bottom left hand corner of the “Run Applescript” action and uncheck “Show action when Run.”
Now you should be good to go…well, almost. You will need to copy the iCal plug in to ~/Library/Workflows/Applications/iCal/ on each of the other computers where it might be needed when iCal triggers that alarm.

Vince

Vince, I feel like a fracking idiot! I had checked that option back when I couldn’t get it to run. Thanks man. Thanks to everyone.

I just save the work flow as an application on my iDisk. Every computer is sync’d to it. On the calendar I created in iCal for Automator I just have a daily appointment that shows up at a certain time. I have it set to run the Automator workflow saved as an application sitting on my iDisk. This way, if I want to change the time of an event, I can just make a schedule change in iCal and I don’t have to worry about anything.

Thanks again! This is going to be one of the handiest workflows I have created so far and inserting AppleScript makes me feel like a “real” Mac user now. :wink: