Other Application Location

I need to be able to do a few things…

One… given an application name … say “XCODE.APP”
a) determine where it is located [in a FolderItem, NIL if it is not available]
b) determine if it is currently running [which of course would be false if not even installed :slight_smile: ]
c) [Extra Credit] what files (if any) that application has open
d) [Extra Credit] be able to shut the app down [with user confirmation of course]

Declares or AppleScript would be acceptable

And (in the spirit of other recent topics)… You all know I have done my homework first :smiley:

I can (kind of) knock off three of these. The problem is that if the application specified is not on the computer then a dialog will pop up to ask the user where the application is located. I will look into how to solve that tomorrow, but hopefully these will help for now.
a) Save the following Applescript code as a script (determineApplicationPath) and drag it into Xojo:

on run {theApp} set thePath to (POSIX path of (path to application theApp)) return thePath as string end run
Xojo code:

dim f as new FolderItem(determineApplicationPath("Xcode.app")) // f is a folder item pointing to Xcode

b) AppleScript (saved as isRunning):

on run {appName}
	if application appName is running then
		set isRunning to true
	else
		set isRunning to false
	end if
	return isRunning as string
end run[/code]
Xojo code:
[code]dim running as Boolean =  if(isRunning("Xcode") = "true", true, false)[/code]

d) AppleScript (quitApp):
[code]on run {appName}
	--ignoring application responses
	tell application appName
		quit
	end tell
	--end ignoring
end run

You will need to uncomment the “ignoring application responses” and “end ignoring” if you want to hard quit the app and not allow the user to save.
Xojo code:

quitApp("Xcode")

Hopefully this helps.

Thanks… I will look into these in the morning…

Check lsof
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html

It is not entirely bullet proof, though. Seems it does not report files opened by TextEdit.

There are so many options… But simply entering lsoft in the terminal lists all sorts of open files.

Check lsof
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html

It is not entirely bullet proof, though. Seems it does not report files opened by TextEdit.

There are so many options… But simply entering lsoft in the terminal lists all sorts of open files.

Dave, is this Mac only?

The API of find out where app is, is Launch Services.

Yes… this will be Mac Only