When i finish to write a script (and test it, and ask him why it not works fine, and ceck Macscripter, and rewrite it usually I save it as a Bundle applications. I make a good icon on it, take some modifications of Info.plist (for version) and, then, I save another copy of it as a readonly application.
So, first bundle is for my testing and edit, and the second is for pubblic use.
So, my idea is to build a script (âHydraâ) that make it for me. I made this, but it doesenât work.
This is my first time to trying to automate AppleScript and I bag you pardon for every strange rowâŚ
(*
Hydra
*)
on open these_items
process_item(these_items)
end open
on run
set these_items to choose file with prompt "Select file" without invisibles
process_item(these_items)
end run
on process_item(these_items)
set {isExt, isFolder, isPack} to {name extension, folder, package folder} of (info for these_items)
if isPack is false and isExt is "scpt" then
-- if the source is a script file
script_item(these_items)
end if
if isPack is true and isExt is "app" then
-- if the source is a bundle application
pack_item(these_items)
end if
end process_item
on script_item(this_item)
set targetFolder to desktop
set targetPath to (targetFolder as Unicode text)
tell application "Script Editor"
open this_item
set documentName to displayed name of (info for this_item)
set targetMix to (targetFolder & documentName & ".app")
save document 1 in targetMix as "application bundle" with run only
close this_item
end tell
end script_item
on pack_item(this_item)
-- something like "script_item" but not for script files, but for .app bundle
-- I have to copy icon and Info.plist from the original to the saving copy
end pack_item
There is something wrong on it, and anytime I try to take a look to the events window, ScriptEditor (Iâm on Leopard) will crash.
Now the script works fine. Final step is to copy two resources from the target bundle to the new bundle. Those resources are Info.plist (inside the Contents folder) and applet.icns or droplet.icns (inside the Resources folder).
Iâve tried to write this
try
set SetFile to the quoted form of POSIX path of (path to resource "droplet.icns") of this_item
on error error_message
display dialog error_message
end try
but AS give me an error like âcanât find a resourceâ. Maybe that âpath to resourceâ is a path to the resource of the script that is running, not the script that is âthis_itemâ.
After that, how can I write to copy a resource from inside a .app to insider another .app: can I use the copy command from the Finder? Does it works also with .app?
UhmâŚ
So, this is that Iâve write.
But the script doesnât seem to find âdroplet.icnsâ: thatâs so stupid, Iâm sure that the file is in the right place
NB: this_item is the original item, targetMix is the item in desktop
set targetMix to (targetFolder & documentName & ".app")
set SetFileor to POSIX path of this_item & "Contents/Resources/" & "droplet.icns"
set SetFileds to POSIX path of targetMix & "/Contents/Resources/"
tell application "Finder"
move document file SetFileor to SetFileds with replacing
end tell
Another problem is command âMoveâ with Finder. This command move the file, but I want to Copy it! Iâve take a look at the leopard Dictionary, and the Copy commando is âNOT AVAILABLE YETâ. So, have I to duplicate the file, move it and rename the copy? It seem so boringâŚ
Model: iMac 2007
AppleScript: 2.2
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11) Gecko/20071128 Camino/1.5.4
Operating System: Mac OS X (10.5)
Ok, thanks Stefank. So, the code are right and it works fine.
I posted all the script, it can be usefull for other user
-- This routine helps Script development to make a run only script from a script file or a bundle application (not run only).
-- Script works fine, but every suggestion is welcome :)
on open these_items
process_item(these_items)
end open
on run
set these_items to choose file with prompt "Select file" without invisibles
process_item(these_items)
end run
on process_item(these_items)
set {isExt, isPack} to {name extension, package folder} of (info for these_items)
if isPack is false and isExt is "scpt" then
-- if the source is a script file
script_item(these_items)
end if
if isPack is true and isExt is "app" then
-- if the source is a bundle application
pack_item(these_items)
end if
end process_item
on script_item(this_item)
tell application "Script Editor"
open this_item
set documentName to displayed name of (info for this_item)
set targetMix to ((path to desktop as text) & documentName & ".app")
save document 1 in targetMix as "application bundle" with run only
close document 1
end tell
end script_item
on pack_item(this_item)
tell application "Script Editor"
open this_item
set documentName to displayed name of (info for this_item)
set targetMix to ((path to desktop as text) & documentName & ".app")
save document 1 in targetMix as "application bundle" with run only
close document 1
end tell
-- Duplicazione file droplet.icns
try
set SetFileor to ((this_item as text) & "Contents:Resources:droplet.icns")
set SetFileds to targetMix & ":Contents:Resources:" as alias
duplicate_routine(SetFileor, SetFileds)
on error
-- Duplicazione file applet.icns
set SetFileor to ((this_item as text) & "Contents:Resources:applet.icns")
set SetFileds to targetMix & ":Contents:Resources:" as alias
duplicate_routine(SetFileor, SetFileds)
end try
-- Duplicazione file Info.plist
set SetFileor to ((this_item as text) & "Contents:Info.plist")
set SetFileds to targetMix & ":Contents:" as alias
duplicate_routine(SetFileor, SetFileds)
end pack_item
on duplicate_routine(SetFileor, SetFileds)
tell application "Finder"
duplicate document file SetFileor to SetFileds with replacing
end tell
end duplicate_routine
Model: iMac 2007
AppleScript: 2.2
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11) Gecko/20071128 Camino/1.5.4
Operating System: Mac OS X (10.5)