Hi all.
I’m developing an applescript for rename files. Part of this script determinate every aspect of the disk of file/s.
This part is called “Barnaba”.
on run
set myfile to choose folder with prompt "Select folder or HD" without invisibles
process_item(myfile)
end run
on open myfile
process_item(myfile)
end open
on process_item(myfile)
tell application "Finder"
try
set this_disk to disk of myfile
set disk_name to name of this_disk
set disk_format to format of this_disk
set disk_jour to journaling enabled of this_disk
set disk_capacity to capacity of this_disk
set disk_free to free space of this_disk
set disk_ejectable to ejectable of this_disk
set disk_local to local volume of this_disk
set disk_startup to startup of this_disk
set disk_priv to ignore privileges of this_disk
display dialog "Nome= " & (disk_name as string) & return & return & "Format= " & (disk_format as string) & return & "Is it journaling? " & (disk_jour as string) & return & "Is it local? " & (disk_local as string) & return & "Is it startup disk? " & (disk_startup as string) & return & "Has it privileges enabled? " & (disk_priv as string)
on error e
display dialog e
-- display dialog "Sorry, no Info"
end try
end tell
end process_item
Barnaba works fine, but I have two different answerif I try to run it from AppleScript and from itself as application bundle.
From AppleScript Format of disk is “Mac OS Extended format”, from application bundle Format of disk is “«constant ****dfh+»”.
This is not a BIG problem, but why I have two different results for the same file/folder?
‘«constant ****dfh+»’ is the compiled token corresponding to the Finder keyword ‘Mac OS Extended format’ that you see in your script. When the script’s running in Script Editor (or, apparently, from Script Menu), the token is decompiled back to the keyword and it’s the keyword that’s coerced to string. When the script’s running as an applet, there’s no facility for decompiling the script, so it’s the token that’s coerced to string and displayed in your dialog.
One solution to this appears to be to do the coercion in a separate sub-script that’s run by the ‘run script’ command. (That is, it’s ‘run script’, rather than the applet itself, which does the coercing.)
on run
set myfile to choose folder with prompt "Select folder or HD" without invisibles
process_item(myfile)
end run
on open myfile
process_item(myfile)
end open
on process_item(myfile)
tell application "Finder"
try
set this_disk to disk of myfile
set disk_name to name of this_disk
set disk_format to format of this_disk
set disk_jour to journaling enabled of this_disk
set disk_capacity to capacity of this_disk
set disk_free to free space of this_disk
set disk_ejectable to ejectable of this_disk
set disk_local to local volume of this_disk
set disk_startup to startup of this_disk
set disk_priv to ignore privileges of this_disk
-- Coerce the disk format keyword to string.
script
tell application "Finder" to return disk_format as string
end script
set disk_format_string to (run script result)
display dialog "Nome= " & (disk_name as string) & return & return & "Format= " & (disk_format_string) & return & "Is it journaling? " & (disk_jour as string) & return & "Is it local? " & (disk_local as string) & return & "Is it startup disk? " & (disk_startup as string) & return & "Has it privileges enabled? " & (disk_priv as string)
on error e
display dialog e
-- display dialog "Sorry, no Info"
end try
end tell
end process_item
set {disk_name, disk_format, disk_jour, disk_free, disk_ejectable, disk_local, disk_startup, disk_priv} to ({name, format, journaling enabled, free space, ejectable, local volume, startup, ignore privileges} of (disk of myfile))
Yes, you are right man!
Now I have only an error in the drop form: strange, because the run handler works fine.
What’s wrong?
on run
set myfile to choose folder with prompt "Select folder or HD" without invisibles
process_item(myfile)
end run
on open myfile
process_item(myfile)
end open
on process_item(myfile)
tell application "Finder"
try
set {disk_name, disk_format, disk_jour, disk_capacity, disk_free, disk_ejectable, disk_local, disk_startup, disk_priv} to ({name, format, journaling enabled, capacity, free space, ejectable, local volume, startup, ignore privileges} of (disk of myfile) as string)
if disk_format contains "dfh+" then
set disk_format to "Mac OS Extended format"
end if
display dialog "Nome= " & disk_name & return & return & "Format= " & disk_format & return & "Is it journaling? " & disk_jour & return & "Is it local? " & disk_local & return & "Is it startup disk? " & disk_startup & return & "Has it privileges enabled? " & disk_priv
on error e
display dialog e
--display dialog "Sorry, no Info"
end try
end tell
end process_item
More then one, I suppose.
If I drop a folder on bundle application error says “Can’t get «class cdis» of {alias “Space:BackUp:”}.” BackUp is a folder of a local Space volume.
This is last version of script.
on run
set myfile to choose folder with prompt "Select folder or HD" without invisibles
process_item(myfile)
end run
on open myfile
process_item(myfile)
end open
on process_item(myfile)
tell application "Finder"
try
set {disk_name, disk_format, disk_jour, disk_capacity, disk_free, disk_ejectable, disk_local, disk_startup, disk_priv} to ({name, format, journaling enabled, capacity, free space, ejectable, local volume, startup, ignore privileges} of (disk of myfile))
if disk_startup then
set disk_startup to " (actual startup disk)"
else
set disk_startup to ""
end if
set disk_format to (disk_format as string)
if disk_format contains "dfh+" then
set disk_format to "¢ Mac OS Extended format"
end if
if disk_jour then
set disk_jour to "¢ Disk is journaling"
else
set disk_jour to "¢ Disk is not journaling"
end if
if disk_ejectable then
set disk_ejectable to "¢ Disk is ejectable"
else
set disk_ejectable to "¢ Disk is not ejectable"
end if
if disk_local then
set disk_local to "¢ Disk is local"
else
set disk_local to "¢ Disk is not local (maybe a network volume?)"
end if
if disk_priv then
set disk_priv to "¢ Privileges are enabled"
else
set disk_priv to "¢ Privileges are ignored"
end if
display dialog disk_name & disk_startup & return & return & disk_format & return & return & disk_jour & return & disk_local & return & disk_priv
on error e
display dialog e
--display dialog "Sorry, can't get info"
end try
end tell
end process_item
the parentheses and as string is the error.
You cannot coerce this kind of a list to a string
For testing it’s better to remove the try blocks to see the errors directly
set {disk_name, disk_format, disk_jour, disk_capacity, disk_free, disk_ejectable, disk_local, disk_startup, disk_priv} to {name, format, journaling enabled, capacity, free space, ejectable, local volume, startup, ignore privileges} of (disk of myfile)
on run
set myfile to choose folder with prompt "Select folder or HD" without invisibles
process_item(myfile)
end run
on open myfiles
process_item(item 1 of myfiles) -- First dropped item (of one or many).
end open
on process_item(myfile)
display dialog "run"
tell application "Finder"
try
set {disk_name, disk_format, disk_jour, disk_capacity, disk_free, disk_ejectable, disk_local, disk_startup, disk_priv} to ({name, format, journaling enabled, capacity, free space, ejectable, local volume, startup, ignore privileges} of (disk of myfile))
if disk_startup then
set disk_startup to " (actual startup disk)"
else
set disk_startup to ""
end if
if ((disk_format as string) contains "dfh+") or ((disk_format as string) is Mac OS Extended format) then
set disk_format to "¢ Mac OS Extended format"
end if
if disk_local is false then
set disk_format to ""
end if
if disk_jour then
set disk_jour to "¢ Disk is journaling"
else
set disk_jour to "¢ Disk is not journaling"
end if
if disk_ejectable then
set disk_ejectable to "¢ Disk is ejectable"
else
set disk_ejectable to "¢ Disk is not ejectable"
end if
if disk_local then
set disk_local to "¢ Disk is local"
else
set disk_local to "¢ Disk is not local (maybe a network volume?)"
end if
if disk_priv then
set disk_priv to "¢ Privileges are enabled"
else
set disk_priv to "¢ Privileges are ignored"
end if
display dialog "\"" & disk_name & "\"" & disk_startup & return & return & disk_format & return & return & disk_jour & return & disk_local & return & disk_priv
on error e
display dialog e
--display dialog "Sorry, can't get info"
end try
end tell
end process_item
THis evening, I try to implement other format string (HFS, ISO etc…), but for now it’s OK