I am having trouble trying to work with a variable in several applications in my Applescript.
First, I teach at a small college in the south. I keep my grade book in Excel (2004) and use Fetch (5) to upload a copy to a Web site so the students can see their grades. (They access their grades through a CGI script and each student has a password so he or she can only see his or her grades.)
I use Applescript to automate the process of saving the Excel files as text then transfer the files to the Web server in Fetch.
I am trying to create a universal (for this script) variable that is declaired at the start of the script then modified by Excel and used by Fetch. In other words, I want to store the names of the files I want uploaded in Excel, have Excel read those name then update the variable names file01, file02, file03 and file04 so that fetch will know while files to upload.
I placed:
global file01
global file02
global file03
global file04
set file01 to “ryryry”
set userhome to “Steve’s HD:Users:mystuff:Desktop:” as text
set whereisgb to “Steve’s HD:Users:mystuff:Documents:Gradebook:Post GB.xls”
tell application “Microsoft Excel”
activate
open workbook workbook file name whereisgb
execute excel 4 macro VB macro name “‘Post GB.xls’!GBWeb()”
quit
end tell
tell application “Fetch”
activate
make new transfer window at beginning with properties {hostname:“xxxxx.xxxxxx.edu”, username:“xxxxx”, password:“xxxxxxxx”, initial folder:“/area51”}
put into transfer window “xxxxxxx.xxxxxx.edu” item alias file01
try
quit
end try
end tell
tell application “Finder”
delete file file01
end tell
in my Applescript.
My Excel macro starts with:
Sub GBWeb()
’
’ GBWeb Macro
’ Macro recorded 11/5/2004 by Steve
’
Lookhere = Range(“D2”).Value
StickitHere = Range(“D3”).Value
If Range(“A7”) <> “” Then
GBNameIn = Range(“A7”).Value
OutGBName = Range(“C7”).Value
file01 = OutGBName
Workbooks.Open FileName:= _
Lookhere + GBNameIn
Range(“AO68”).Select
ActiveWorkbook.SaveAs FileName:= _
StickitHere + OutGBName, FileFormat:=xlText, _
CreateBackup:=False
ActiveWorkbook.Close
End If
and this continues on where the value in D2 is the path to where the gradesbooks are stored on my Mac, D3 is the path to the desktop (where Fetch will find the text version of each gradebook), A7 hold the name of the first gradebook Excel file and C7 is the name of the text version Fetch should pick up on the desktop.
I am trying to set the contents of variable file01 in this section of the Excel macro, but the variable appears to be local to only Excel and it doesn’t alter the contents for the rest of the script as Fetch and Finder seem to think the contents of file01 are ryryry.
The Excel macro works great, except that it doesn’t update the variable file01. The Applescript also works, except that the variable file01 is never updated as it runs.
This is probably an easy question that I should already know, how do I create a variable that is used in several applications and that the running applications can update for remaining application?
Thank you for your help.
//steve
Model: iBook G4
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)