Re: Help please
Re: Help please
- Subject: Re: Help please
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 15 Nov 2002 17:41:11 -0800
On 11/14/02 11:40 AM, "Amir Bozorgzadeh" <email@hidden> wrote:
>
I am writing a simple script to delete a preference file from a users
>
home directory. Thanks to this list I finally have it working but I
>
am now presented with another problem. How can I attach this so that
>
it runs after Word is closed? Is there a way to do this? Or having it
>
run when Word is launched is even better. The reason is that the
>
students in the lab may not launch word from my script but most will
>
probably launch Word from a file that is already created. Here is the
>
script that works now but I will rewrite if I can figure out how to
>
attach it to the application Word.
>
>
tell application "Finder"
>
try
>
delete file "Office Registration Cache X" in folder
>
"Microsoft" of folder "Preferences" of folder "Library" of folder
>
(path to current user folder)
>
empty trash
>
end try
>
end tell
>
>
Essentially my thought was is there a way I can attach it to the
>
application Word so that every time it launches it runs this script.
You can do it through Word's VBA. There are four, I think, VBA 'Events'
(Auto Macros) which are triggered automatically: one of those is at launch,
another at close. One could be installed in Word's Normal template as a
macro which called that script via the 'MacScript' command. Or even easier
would be to make a template to place in the Word Startup folder. (That's in
Microsoft Office (X or 2001 or 98)/Office/Startup/Word/.) Any macro in that
template will run when Word starts up.
Incidentally, you should not use the 'path to' addition inside he Finder.
You only need the Finder for deleting the file and emptying the trash. You
should get the path this way. You can omit 'from user domain' since there
are no system-wide or computer-wide Preferences folder, only user
preferences.
set filePath to ((path to preferences as string) & "Microsoft:Office
Registration Cache X")
tell application "Finder"
delete file filePath
empty trash
end tell
That converts to VBA like this:
Sub DeletePrefs()
MacScript ("set filePath to ((path to preferences as string) &
""Microsoft:Office Registration Cache X"")" & vbCr & _ ' one line
" tell application ""Finder""" & vbCr & _
" delete file filePath" & vbCr & _
" empty trash" & vbCr & _
" end tell")
End Sub
But I don't think that deleting prefs AFTER the app has opened is going to
do anything until you close Word. Not what you want. So do it as an
AutoExit Macro - you have to call it AutoExit:
Sub AutoExit()
MacScript ("set filePath to ((path to preferences as string) &
""Microsoft:Office Registration Cache X"")" & vbCr & _ ' one line
" tell application ""Finder""" & vbCr & _
" delete file filePath" & vbCr & _
" empty trash" & vbCr & _
" end tell")
End Sub
Paste that into Visual Basic Editor (Tools/Macro/Macros/Create) for a new
blank Document which you've just opened. Fix the (first) long line mangled
by this email (make it one long line) and save the macro in the new document
which you can call "Delete Prefs". Save or put the document in the Word
Startup Folder as described above.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Help please (From: Amir Bozorgzadeh <email@hidden>) |