 |
 |
AppleScript question
|
 |
|
 |
|
Senior User
Join Date: Feb 2004
Location: Lost in a "plus" world
Status:
Offline
|
|
I am attempting to modify an Entourage 2004 applescript that inserts a text file into the body of a message, seen here:
Code:
(*
Insert Text File...
Copyright (c) Microsoft Corporation. All rights reserved.
Inserts a text file into the current message
If this script is saved as an applet, you can drop files on the applet to have
them inserted
*)
on run {}
set theFile to choose file with prompt ¬
"Select the file to insert"
insertFile(theFile)
end run
on open (fileList)
repeat with theFile in fileList
insertFile(theFile)
end repeat
end open
on insertFile(theFile)
try
set fileRef to open for access theFile
set textToInsert to read fileRef
on error errString
display dialog "There was an error reading the file because:" & errString ¬
buttons {"OK"}
return
end try
try
tell application "Microsoft Entourage"
set selection to textToInsert
end tell
on error errString
display dialog "This script can only insert into the body of a message" buttons {"OK"}
return
end try
end insertFile
What I want to change is, instead of it prompting for a file, I'd like to hard code a link to a specific file so that it automatically inserts the same txt file each time.
Code:
on run {}
set theFile to choose file with prompt ¬
"Select the file to insert"
insertFile(theFile)
end run
I am having trouble figuring out exactly how to do this. I would like to set it to "~/Documents/Microsoft User Data/Entourage.txt"
This is just a one-time thing I would like to be able to do in AppleScript. Any help would be much appreciated. It's difficult to google for since I'm not even sure exactly what I am asking. Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
Remove the line 'set theFile to choose file with prompt "Select the file to insert"' entirely. Change insertFile(theFile) to just insertFile(). Change "on insertFile(theFile)" to "on insertFile()". Change "set fileRef to open for access theFile" to 'set fileRef to open for access file "Hard Drive Name:Desktop:file.txt"'
That, or something like it, should do it 
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2004
Location: Lost in a "plus" world
Status:
Offline
|
|
This works great and I really appreciate it, however, I would like to be able to user the relative home directory path if possible, usually ~/, however, no combination of this seems to work (file not found error). If I hard code the path from root, it works, but I would prefer to use relative home directory because this modified script will be used by several people.
Thanks in advance!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2004
Location: Lost in a "plus" world
Status:
Offline
|
|
Code:
set filePath to POSIX path of (path to home folder) & "Documents/Microsoft User Data/Entourage.txt"
set fileRef to open for access file filePath
I'm stuck here... getting the error "End of file error" 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
Try this:
Code:
set filePath to (path to home folder) & "Documents:Microsoft User Data:Entourage.txt" as string
set fileRef to open for access (a reference to filePath)
Alternatively, if you want to skip a couple steps, you can just do:
Code:
do shell script "cat ~/Desktop/poker.txt"
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2004
Location: Lost in a "plus" world
Status:
Offline
|
|
LOL I feel so stupid. I could not get that to work.
Thanks for your help though!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |