I guess i am still wondering why the result for combined_file gives an POSIX result when the targeted file is on a volume, but a HFS result when it is under the user’s home account.
I will have a play around to try and force to HFS.
The answer is because Mac os is organized in a certain folder order.
The entire file system is build with nested folders. You need to know where a folder is stored in, to get its contents. Consider to work with alternatives, like posix paths too.
set f to ((path to startup disk) & "Volumes:" as text)
choose file default location alias f
Thanks for the replies. Sorry about delayed reply. Have been travelling. USB key is windows format. I amnot near my mac for a few days so will not be able to test until next week.
Just reverting on this. Have made progress but do not yet have answer. Stefan, your syntax did not work for me. Mouramartin’s did, but has not produced a solution yet.
set combined_file to (duplicate combined_file)
combined_file as alias
This script duplicates fine.
But when I rename the combined file, the new name is not reflected in combined_file. Combined_file retains the original duplicated file name.
Thus:
set combined_file to alias "DATA_STICK:untitled folder:Notes Tdshniques 14.14.52.pdf"
tell application "Finder"
set combined_file to (duplicate combined_file)
combined_file as alias
set name of combined_file to "ok" & ".pdf"
end tell
…duplicates the targeted file and renames it correctly “ok.pdf”, but the value returned for combined_file reflects the original name and not “ok.pdf”. So, again, rest of my script borks as combined_file does not point to “ok.pdf”
BYW, this is a FAT32 issue as my original script worked fine on my internal disk, just the USB keys in FAT32 giving problems.
Can anyone explain why when I rename the file as above, it is renamed (appears in Finder as “ok.pdf”) but combined_file does not reflect this change.
I feel that I have the explanation of what you described
Trying to reproduce it, I ran this script :
# Part #1
tell application "Finder"
activate
select disk "TRANSCEND"
end tell # Finder
tell application "System Events" to tell application process "Finder"
keystroke "i" using {command down}
tell window 1
title
--> "Infos sur TRANSCEND"
class of UI elements
--> {button, button, button, scroll area, image, static text}
value of static text 12 of first scroll area
--> "Format :"
value of static text 13 of first scroll area
--> "MS-DOS (FAT16)"
end tell # window 1
end tell # System Events & process
# Part #2
set combined_file to "TRANSCEND:dossier sans titre:abo.pdf" as alias
set newName to do shell script "date +%Y%m%d_%H%M%S.pdf"
--> "20121013_165855.pdf"
tell application "Finder"
(container of combined_file) as text
--> "TRANSCEND:dossier sans titre:"
set newPath to result & newName
log newPath
(*TRANSCEND:dossier sans titre:20121013_165855.pdf*)
set new_file to duplicate combined_file
--> document file "abo copie.pdf" of folder "dossier sans titre" of disk "TRANSCEND"
--> error number 0
set new_file to new_file as alias
# with a script which never called System Events return a HFS path
--> alias "TRANSCEND:dossier sans titre:abo copie.pdf"
# with a script which ran at least once System Events return a Unix like path
--> alias "/Volumes/TRANSCEND/dossier sans titre/abo copie.pdf"
set name of new_file to newName
--> "20121013_164938.pdf"
log combined_file
(*alias TRANSCEND:dossier sans titre:abo.pdf*)
log new_file
# with a script which never called System Events return a HFS path
(*alias TRANSCEND:dossier sans titre:abo copie.pdf*)
# with a script which ran at least once System Events return a Unix like path
(*alias /Volumes/TRANSCEND/dossier sans titre/abo copie.pdf*)
set new_file to newPath as alias
log new_file
(*alias TRANSCEND:dossier sans titre:20121013_165855.pdf*)
end tell
# Part #3
set newName to do shell script "date +%Y%m%d_%H%M%S.pdf"
--> "20121013_165901.pdf"
tell application "System Events"
path of container of combined_file
--> "TRANSCEND:dossier sans titre:"
end tell # System Events
set newPath to result & newName
do shell script "cp " & quoted form of POSIX path of combined_file & space & quoted form of POSIX path of newPath
set new_file to newPath as alias
--> alias "TRANSCEND:dossier sans titre:20121013_165901.pdf"
# Part #4
set combined_file to (path to desktop as text) & "Install Logs:dossier sans titre:abo.pdf" as alias
set newName to do shell script "date +%Y%m%d_%H%M%S.pdf"
--> "20121013_165906.pdf"
tell application "Finder"
(container of combined_file) as text
--> "Macintosh HD:Users:myAccount:Desktop:Install Logs:dossier sans titre:"
set newPath to result & newName
log newPath
(*Macintosh HD:Users:yvankoenig:Desktop:Install Logs:dossier sans titre:20121013_165906.pdf*)
set new_file to duplicate combined_file
--> document file "abo copie.pdf" of folder "dossier sans titre" of folder "Install Logs" of folder "Desktop" of folder "yvankoenig" of folder "Users" of startup disk
--> error number 0
set name of new_file to newName
--> "20121013_165906.pdf"
log combined_file
(*alias Macintosh HD:Users:myAccount:Desktop:Install Logs:dossier sans titre:abo.pdf*)
log new_file
(*document file abo copie.pdf of folder dossier sans titre of folder Install Logs of folder Desktop of folder myAccount of folder Users of startup disk*)
set new_file to newPath as alias
-->alias "Macintosh HD:Users:yvankoenig:Desktop:Install Logs:dossier sans titre:20121013_165906.pdf"
end tell
The 1st part grab the format applied to my memory stick, here “MS-DOS (FAT16)”.
The 2nd part achieve what you described upon a file is stored on the memory stick.
You’re right, renaming the copy doesn’t change the pathname stored in variable pointing to.
As I wrote in the comments, the script behaved differently if it never triggered System Events or if it did.
The 3rd part achieve what you describe without triggering the infamous Finder.
You will see that with this scheme There is not the puzzling → error number 0 returned by the Finder after duplicate.
The 4th part achieve what you described to a file stored on the internal HD.
In this case, the fact that System Events was triggered or wasn’t changes nothing.
Yvan KOENIG (VALLAURIS, France) samedi 13 octobre 2012 17:21:56
Thanks for the above comments. The code in post 7 did not work any differently to a straight duplication command, Stefan.
What I did in the end was use Yvan’s call to System Events to get the path, and force the name change into combined_file:
tell application "Finder
-----> Rest of script
tell application "System Events"
set filepath to path of container of combined_file as text
end tell
set combined_file to (duplicate combined_file) as alias
set name of combined_file to newname & ".pdf"
set combined_file to filepath & newname & ".pdf" as alias
----->
end tell
Combined_file then works as expected for the rest of the script whether the targeted file in on internal drive or on FAT32 volume.