Launch apps in backgound

I have a script that prints a .ps file to a watched folder. What I can do is activate 2 other apps distiller and internet explorer if they are not already running. What I would like to know is it possible to have if not running launch behind the active app. Also is it possible to enter text into fields of a loaded web page. It may be possible to pick up a text file in my current script and link to the web text fields. Is any of this possible? Many thanks

property URN : ""
set DestFolder to "Marks-G5:Users:marklarsen:Desktop:Adfast PDF's:In:" as text
-- Here is where I want to launch distiller in background
-- Here is where I want to launch Internet Explorer in background
tell application "QuarkXPress"
	tell document 1
		set MyURN to "Please type in the URNnumber."
		set URNnumber to text returned of (display dialog MyURN default answer URN with icon note)
		set vertical measure to millimeters
		set horizontal measure to millimeters
		set MyDocWidth to width of bounds of current page
		set MyDocHeight to height of bounds of current page
		tell print setup
			set printer type to "Adobe PDF"
			set paper width to MyDocWidth
			set paper height to MyDocHeight
			set bleed to 0 as millimeter units
			set orientation to portrait
			set page position to center position
			set print colors to composite CMYK
			set resolution to 2400
			set print spreads to false
			set reduce or enlarge to "100%"
			set registration marks to off
			set include blank pages to true
		end tell
		set filePath to DestFolder & URNnumber & ".ps"
		print PostScript file filePath
	end tell
end tell
tell application "Acrobat Distiller 6.0.2"
	activate
end tell
tell application "Internet Explorer"
	Activate
	OpenURL "http://www.adfast.co.uk/upload.cfm"
	-- Here I want to enter text to fields may be from text file.
	-- the fields can be navigated to using "tabs"
	-- I would like to set the browse for file to alias of the result of above.
end tell

I haven’t found a way to do this. What you want is a command to launch the app but not actually make it active. As far as I can tell, there isn’t a command to do that. What I usually do is launch tell the other apps to become active so they launch and then tell Quark to become active so it instantly jumps to the front of the other ones. That’s not exactly a solution but essentially does the same thing.


tell application "Acrobat Distiller 6.0.2"
   activate
end tell
tell application "Internet Explorer"
   Activate
end tell
set PathToDesktop to path to the desktop as text
	tell application "QuarkXPress"
		activate
--   etc...
end tell

On a related note, I recently figured out how to tell Distiller directly to distill a PDF of a Quark PS file without using a watched folder. I like it better as I can easily give the script out to others without having to set up their Distiller hot folder for it to work. Here it is if you want to check it out. Its set up as a droplet that can take one or multiple drag-and-dropped Quark files (or a folder full of Quark files).


on open these_items
	tell application "Acrobat Distiller 7.0"
		activate
	end tell
	tell application "QuarkXPress"
		activate
	end tell
	tell application "Finder"
		activate
		if not (exists folder "PDF Folder") then
			make new folder at desktop with properties {name:"PDF Folder"}
		end if
	end tell
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) then
			my process_item(this_item)
		end if
	end repeat
	beep 2
	tell application "Finder"
		activate
		try
			open folder "PDF Folder"
		end try
		display dialog ("Finished!") buttons " " giving up after 1
	end tell
end open

-- this sub-routine processes folders
on process_folder(this_folder)
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) then
			my process_item(this_item)
		end if
	end repeat
end process_folder

-- this sub-routine prints the files
on process_item(this_item)
	tell application "System Events"
		set the item_info to info for this_item
		if (alias of the item_info is true) then
			display dialog "No aliases!" buttons "Cancel"
		end if
		if (kind of item_info starts with "Quark") then
		else
			display dialog "This file is not a Quark document!" buttons "Cancel" default button "Cancel" with icon 0
		end if
	end tell
	tell application "QuarkXPress"
		open this_item use doc prefs yes remap fonts ask do auto picture import yes
		delay 1
		my make_ps()
	end tell
end process_item

on make_ps()
	set PathToDesktop to path to the desktop as text
	tell application "QuarkXPress"
		activate
		delay 2
		tell custom bleeds setup 1 of document 1
			set EPS bleed type to symmetric
			set EPS bleed to 0
			set bleed type to symmetric
			set bleed to 0
			set bleed clipping to false
		end tell
		tell front document
			set horizontal measure to inches
			set vertical measure to inches
			set DocWidth to the page width of it as real
			set DocHeight to the page height of it as real
			tell print setup
				set printer type to "AdobePDF 7.0"
				set paper size to "custom"
				set paper height to DocHeight
				set paper width to DocWidth
				set orientation to portrait
				set registration marks to off
				set separation to false
				set tiling to off
				set page position to left position
				set paper offset to 0
				set page gap to 0
				set reduce or enlarge to 100
				set fit in area to false
				set include blank pages to false
				set print thumbnails to false
				set print colors as grays to false
				set back to front to false
				set print spreads to false
				set page sequence to all pages
				set flip horizontal to false
				set flip vertical to false
				set invert image to false
				set print quality to normal
				set print colors to composite CMYK
				set data format to binary data
				set collate to false
			end tell
		end tell
		set myName to (name of the front document) as text
		set AppleScript's text item delimiters to {"."}
		set fileBase to first text item of (myName as string)
		set PS_file_path to (PathToDesktop & "PDF Folder:" & fileBase & ".ps") as text
		print front document PostScript file PS_file_path
		delay 1
		close document myName saving no
	end tell
	tell application "Finder"
		repeat while not (exists file (PathToDesktop & "PDF Folder:" & fileBase & ".ps"))
			delay 1
		end repeat
	end tell
	tell application "Acrobat Distiller 7.0"
		set POSIXPath2PSFile to POSIX path of (PS_file_path as alias)
		set PathToStndDistill to POSIX path of (("Macintosh HD:Library:Application Support:Adobe PDF:Settings:Standard.joboptions") as alias)
		Distill sourcePath POSIXPath2PSFile adobePDFSettingsPath PathToStndDistill
	end tell
	delay 1
	tell application "Finder"
		repeat while not (exists file (PathToDesktop & "PDF Folder:" & fileBase & ".pdf"))
			delay 1
		end repeat
		try
			delete file PS_file_path
		end try
	end tell
end make_ps

Matt-boy thanks for some further insight into this. The first part I could do but would have preferred not to use activate. I recall seeing something about running a script without displaying it I will have a trawl through the older posts. I will keep your script as that too will come in useful. The scripting option for distiller I saw in one of your previous posts and was keeping as an option anyhow but thanks again. Is the using POSIX path in distiller still available to the none pro version?

Had a second thought on this and could I have an if distiller is not already active, activate and minimize to dock.

Matt-Boy, I don’t know what a “POSIX path” is but heres how I had it working not sure if this will make any difference.

tell application "Acrobat Distiller 6.0.2"
	activate
	Distill sourcePath POSIX path of (path to home folder from user domain) & "Desktop/test.eps" destinationPath POSIX path of (path to home folder from user domain) & "Desktop/" adobePDFSettingsPath POSIX path of (path to home folder from user domain) & "Desktop/AdFast.joboptions"
end tell

POSIX path just means that the full path has its subfolders indicated by a “/” rather than AppleScripts standard “:”. If you check Distiller’s dictionary, it indicates that it needs a POSIX path. Not sure why when most other apps don’t ask for it but that’s just that way this one works.

If you want to check if Distiller is already running, I believe the syntax is this:


tell application "System Events"
if not (exists process "Acrobat Distiller 6.0.2") then
tell application "Acrobat Distiller 6.0.2"
activate
end tell
end if
end tell

Matt-Boy, thanks once again now I understand the POSIX path, never seen this used else where. Also that was the exact piece of code that I was trying to recall.

Hi guys.

The following command should generally launch a target application in the background (although the behaviour of certain apps may vary). You shouldn’t normally need to check for the presence of the app first.

launch application "TextEdit" (* or whatever *)

Hi,

Also, I don’t have the apps you mentioned, but you can try using one of the window properties.

tell application “iTunes”
launch
set collapsed of front window to true
end tell

or if more than one window:

tell application “iTunes”
launch
set collapsed of every window to true
end tell

gl,