delete doesn't delete !
delete doesn't delete !
- Subject: delete doesn't delete !
- From: KOENIG Yvan <email@hidden>
- Date: Tue, 22 Apr 2008 19:00:49 +0200
Hello
I encounter a surprising odd behaviour.
I wrote a script which batch convert AppleWorks spreadsheets into
Numbers documents.
All works flawlessly minus a small piece of code.
…
set pY to dossierDeStockage & nomNumbers
tell application "System Events" to if exists (file pY) then set name
of file pY to (text 1 thru -(1 + (length of theExt)) of nomNumbers) &
my horoDateur(modification date of file pY) & "." & theExt
tell application "Finder" to duplicate file path_numbers to folder
dossierDeStockage (*
• before 10.5, System Events is unable to move *)
my wait4File(dossierDeStockage & nomNumbers)
tell application "System Events" to if exists file path_numbers then
delete file path_numbers
…
(* =============
• Build a stamp from the modification date_time
*)
on horoDateur(dt)
local annee, mois, jour, lHeure, lesSecondes, lesMinutes
set annee to year of dt
set mois to month of dt as number (* existe depuis 10.4 *)
set jour to day of dt
set lHeure to time of dt
set lesSecondes to (lHeure mod 60)
set lHeure to round (lHeure div 60)
set lesMinutes to (lHeure mod 60)
set lHeure to round (lHeure div 60)
return "_" & annee & text -2 thru -1 of ("00" & mois) & text -2
thru -1 of ("00" & jour) & "-" & text -2 thru -1 of ("00" & lHeure) &
text -2 thru -1 of ("00" & lesMinutes) & text -2 thru -1 of ("00" &
lesSecondes) (*
• Here, the stamp is "_YYYYMMDD-hhmm" *)
end horoDateur
(* =============
• Wait that the file is completely written on disk
*)
on wait4File(p)
local oldSize, newSize
set oldSize to 0
repeat
tell application "System Events" to set newSize to physical size of
file p
if oldSize < newSize then
set oldSize to newSize
else
exit repeat
end if
end repeat
end wait4File
-- =============
On execution I got this report:
tell application "System Events"
set name of file "Caviar Macintosh
HD:Users:yvankoenig:Desktop:wasBOBO_nowNumbers:Chèques YK
2007.numbers" to "Chèques YK 2007._20080422-183451.numbers"
end tell
tell application "Finder"
copy file "Caviar Macintosh HD:Users:yvankoenig:Desktop:Chèques YK
2007.numbers" to folder "Caviar Macintosh
HD:Users:yvankoenig:Desktop:wasBOBO_nowNumbers:"
document file "Chèques YK 2007.numbers" of folder
"wasBOBO_nowNumbers" of folder "Desktop" of folder "yvankoenig" of
folder "Users" of startup disk
end tell
tell application "System Events"
get physical size of file "Caviar Macintosh
HD:Users:yvankoenig:Desktop:wasBOBO_nowNumbers:Chèques YK 2007.numbers"
6.30784E+5
get physical size of file "Caviar Macintosh
HD:Users:yvankoenig:Desktop:wasBOBO_nowNumbers:Chèques YK 2007.numbers"
6.30784E+5
exists file "Caviar Macintosh HD:Users:yvankoenig:Desktop:Chèques YK
2007.numbers"
true
delete file "Caviar Macintosh HD:Users:yvankoenig:Desktop:Chèques YK
2007.numbers"
end tell
I don't understand why, but the file is not deleted.
I introduced the wait4file() call to try to get rid of that but it
changes nothing.
Of course, I have a workaround: use the Finder to delete but I prefer
use System Events which doesn't put the file in the trash.
I just add that I am running 10.4.11
Yvan KOENIG (from FRANCE mardi 22 avril 2008 19:00:26)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden