Re: Getting Applications Info
Re: Getting Applications Info
- Subject: Re: Getting Applications Info
- From: "J. B. Stewart" <email@hidden>
- Date: Wed, 21 Mar 2001 18:18:51 -0500
At 2:14 PM -0500 3/21/01, Jose Luis Paredes wrote:
>
Ok here's the initial script I have to collect info on the
>
applications residing in a drive. I need to put file that I stored
>
the info in the desktop, but no matter what I try the file always
>
saves inside the system folder. Eventually I will add something to
>
check for multiple copies of the software or even the software
>
missing. Any ideas would be appreciated. Thanks
>
>
tell application "Finder"
>
activate
>
>
open for access file "Applications Report" with write permission
>
>
set i to 1
>
repeat while i > 4
>
if i = 1 then
>
set ApplicationCreatorType to "8BIM"
>
else if i = 2 then
>
set ApplicationCreatorType to "XCEL"
>
else if i = 3 then
>
set ApplicationCreatorType to "PPT3"
>
else if i = 4 then
>
set ApplicationCreatorType to "MSWD"
>
>
end if
>
>
set the ApplicationName to (get name of (info for
>
application file id ApplicationCreatorType))
>
set the ApplicationVersion to (get short version of
>
(info for application file id ApplicationCreatorType))
>
set the ApplicationInfo to (the ApplicationName &
>
space & the ApplicationVersion & return) as string
>
write ApplicationInfo to file "Applications Report"
>
set i to i + 1
>
end repeat
>
>
close access file "Applications Report"
>
end tell
>
--
>
>
**************************
>
Jose Luis Paredes
Jose,
1) There is almost nothing in your script that requires the Finder so you don't need to place the script in a Finder tell. If you want to make sure the Finder is the active application then use something like this instead of a tell/end tell statement.->
Tell application "Finder" to activate
2) You haven't told the OS to save the file on the desktop, use ->
set LfilePath to (path to desktop as string) & "Applications Report"
3) There has been a lot of discussion on this list about the best way to use "open for access" and it would appear to be the following method ->
set LfileRef to open for access file LfilePath with write permission
4) You only need to get the "info for" an application once, store it into a variable and extract what you need from the variable.
5) file read/writes are safest in a try/end try error handler, this can close the file access if something goes wrong.
Here is a bit of a rewrite of your script. It's bit of modularizing to make for easier maintenance.
It places a list at the top of the script for your creator codes and makes it easy to add to or replace them.
It moves the information gathering into a handler.
The repeat loop is now based on the number of items in a list so it will reflect changes to the list automatically.
Lastly it opens the new file once, writes to it once and then closes it, all done quickly.
(* Begin Script *)
set LtypeList to {"8BIM", "XCEL", "PPT3", "MSWD"}
set LinfoList to {}
set LfilePath to (path to desktop as string) & "Applications Report"
try
set LfileRef to open for access file LfilePath with write permission
repeat with cCode in LtypeList
set end of LinfoList to myGetInfo(contents of cCode)
end repeat
set LinfoList to LinfoList as string
write LinfoList to LfileRef
close access LfileRef
on error errmsg number errnum
close access LfileRef
display dialog errmsg
end try
on myGetInfo(cType)
tell application "Finder" to set temp to (application file id cType)
set AppInfo to info for temp
set ApplicationName to name of AppInfo
set the ApplicationVersion to (get short version of AppInfo)
set the ApplicationInfo to (the ApplicationName & space & the ApplicationVersion & return)
end myGetInfo
(* End Script *)
Others on the list will undoubtedly have other methods but if you have any questions on mine feel free to contact me directly.
John