If "something" then ....do "nothing"?

Working on a couple little scripts and wondering what the proper way to tell a script to “do nothing” is. Is it alright to leave nothing after “then”?

example:

if variable > 2 then
else
	tell application "safari" to activate
end if

The scripts seem to work fine without defining anything for the script to do but am I running the risk of an error or future problems?

Thanks

Perfectly correct, and sometimes indeed simpler than


if x ≤ 2 then  ....

beauty thanks!

Yes, it is.

Also:

if not (variable > 2) then
	tell application "Safari" to activate
end if

That’s an odd usage though (you could just use a different operator, like Eelco did); Consider this instead:

choose file without invisibles
set {folder:isFolder} to info for result

if not isFolder then
	-- If you choose a bundle (e.g. an application), you won't see this dialog
	display dialog "That item is not a folder."
end if

Sorry I should have mentioned that that was a completely random example! I Just threw in a fake variable and action to get the point across.

Thanks though!

or

if variable > 2 is false then... 

because all comparisions result a boolean value

Interestingly, testing if something’s true and branching if it’s not is minutely faster than testing if it’s not true and not branching if it isn’t! :wink: That is:

if (variable > 2) then
else
	-- Do something.
end if

. is marginally faster than:

if not (variable > 2) then -- or any syntactical variant of this.
	-- Do something.
end tell

The difference isn’t enough to make it worth doing in normal circumstances, but it can help in intensively repeating processes, such as sorts. I think that when testing if something’s not so, AppleScript tests if it is so and then ‘nots’ the result before deciding whether or . er . not to branch. :rolleyes: