the thinking is the paragraph Scripting Addition Security in AppleScript Release Notes
thanks. Always learning.
Eric
Stefan, I am still fighting with this. I realise that if the file does not exist, the script will try to execute the rest (there is a whole block behind this that will send the file per email, trash it etc.). How do I stop this if there is no file in the first place?
Put all the rest between if and else or use a handler
Hello,
Try this.
Insert it as a replacement for your previous finder statement that attempted to rename the file. And, I think you should specify the folder where your file should exist, as the working directory of your applet might vary. (I am not sure about this, but a full file reference is always a good practice, when you know where it is to be created.
set weekName to "week " & (do shell script "date +%U" & ".gz")
local probe
try
tell application "Finder" to set probe to file "gespr_dat.csv.gz" as alias
on error
log "full hfs path to gespr_dat.csv.gz didn't exist!"
delay 0.5
repeat
try
tell application "Finder"
set probe to file "gespr_dat.csv.gz" as alias
set the name of file "gespr_dat.csv.gz" to weekName
end tell
exit repeat
on error
delay 0.5
end try
end repeat
end try
Hallo, I am a bit stuck. I suppose I need to put in the path of where the file is. Correct?
Like so?
set probe to "/Home/Users/xyz/Desktop/gespr_dat.csv.gz" as alias
Because that does not work. It just hangs.
Eric
If the file is on desktop, then there is no need to specify the folder in a Finder tell block,
because the “root” folder of the Finder is the desktop folder of the current user.
The command exists might be better than forcing errors and the Finder is not needed for the alias coercion.
System Events is also able to perform file system operations so the Finder doesn’t get blocked
set time_out to 10
tell application "System Events"
repeat until (exists file "gespr_dat.csv.gz" of desktop folder) or (time_out is 0)
delay 1.0
set time_out to time_out - 1
end repeat
if time_out = 0 then
log "operation timed out"
else
set name of file "gespr_dat.csv.gz" of desktop folder to weekName
end if
end tell
Hello.
Nope, that is a Posix path you should use a Hfs path the ones you see in the log with colons inside it.
But you should really read StefanK’s post, if your file is created on Desktop, and not in the downloads folder, then you are fine with specifying just the file.
Nice timeout operation!! I was not sure if you can rename a file when it is busy or not. My approach also covered that possibility, when I wrote my solution, (which would have lead to even more code if I was to consider that together with exists.
But since StefanK’s code, doesn’t have a clause for that, I trust it to not be the case, that there is any problems in renaming a “busy file”
You should really go for his approach, as he has implemented a time-out which I errantly has not.
System events is always a better choice than finder, as Finder are more likely to be bogged down with something.
Hallo Stefan
Thanks for all that. I used your second script and this works. Thanks.
Eric
Greetings McUsr
I did.
Thanks.