I am the script, the script is me

Is there anyway for an AppleScript to refer to itself?

Something like

this activate
me activate

Thanks

Steve

dont know what you mean but if you


activate
display dialog "Hello"

It will put the dialog at the front of the window. is that what you meant other than that i dont know sorry

I guess I should have been more clear. I am running a script which automates some processes in Photoshop. I’m blocking errors with the try command and then have a display dialog to display what the error is and then automatically close. Problem is that when the dialog box is initiated I am in the Photoshop tell command and have to manually click on script editor to get back to my applescript - which kind of defeats the point of having the error message automatically close. Here’s my script if that wasn’t too clear:

if fileType = "PDF " then
set moveFileContents to true
try
–converting file to jpeg
tell application “Adobe Photoshop 7.0”
activate
with timeout of 30 seconds
open thisFilePath showing dialogs never
end timeout
set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte, quality:10}
save current document in thisFilePath as JPEG with options myOptions appending lowercase extension with copying
close current document saving no
end tell
on error errMsg number errNum
( It’s at this point I would like to switch back to my script, before I display the error message)
display dialog “There was an error with” & thisFile & return & return & “::::::::::::::::::::::::::::::::::::::” & return & ¬
“Error Number:” & errNum & return & "Error: " & errMsg & return & return & “::::::::::::::::::::::::::::::::::::::” giving up after 5
end try
end if --checking for pdf[/b]

Put this in your error trap before the dialog.

tell application "Script Editor" to activate

what i have said should work, as you are outside the tell blocks.

i.e.


end tell <--end tell
on error errMsg number errNum 
(* It's at this point I would like to switch back to my script, before I display the error message*)

activate  <---- outside tell
display dialog "There was an error with" & thisFile & return & return & "::::::::::::::::::::::::::::::::::::::" & return & ¬ 
"Error Number:" & errNum & return & "Error: " & errMsg & return & return & "::::::::::::::::::::::::::::::::::::::" giving up after 5 
end try 

the activate does what rob says but is quicker really, if only by alittle and less typing, i have used that in my code.


tell application "Internet Explorer"
		OpenURL "http://www.bl.....s.com/admin/libadd.asp"
		set webImage to do script "window.document.forms[0].elements[0].value"
		--so the image number is up to date
		my incrementFile("" & numberIm & "", imageFile, true)
	end tell <----end tell
	if webImage < numberIm then
		activate  <---- outside tell
		display dialog "The numbers do not match" & return & "It appears you have missed a file whilst uploading, please look back through the last number of uploads and find the missing file" buttons {"OK"}
	else if webImage > numberIm then
		activate
display dialog

Catch my drift?

Thanks guys.

Unless you actually need to bring Script Editor to the front for other reasons, you could simply tell the current frontmost application to display the message:

try

  cause of problem

on error errMsg number errNum
  tell application (path to frontmost application as string)
    display dialog "There was an error with " & thisFile & return & return & "::::::::::::::::::::::::::::::::::::::" & return & ¬
      "Error Number:" & errNum & return & "Error: " & errMsg & return & return & "::::::::::::::::::::::::::::::::::::::" giving up after 5
  end tell
end try

You don’t actually need to ‘activate’ any app at all. You can simplly:

 tell me to display dialog "...."

This will pop up just the error dialog in the script’s context, but won’t cause an application switch. Probably the easiest and quickest way to deal with the problem.

(Note: might have different effects depending on whether you’re running the script within a script editor or as a standalone application)