Compile an application with ScriptEditor by AppleScript ?!?

Hi all.

When i finish to write a script (and test it, and ask him why it not works fine, and ceck Macscripter, and rewrite it :wink: 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.

Thnx in advance for avery (little) help

bye

Hi Matteo,

the path of targetFolder is wrong
desktop is only the constant, not the path

set targetFolder to path to desktop as text

Yeah, right!
Tnx a lot Stefank

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?

Yes, path to resource points to the resource folder of the running script
btw: this_item is the .scpt file not the created application file

use something like this

set SetFile to POSIX path of targetMix & "/Contents/Resources/"

or the HFS counterpart

set SetFile to targetMix & ":Contents:Resources:"

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 :slight_smile:

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… :frowning:

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)

This cannot work, because the Finder needs a HFS path (colon separated), not a POSIX path.
like this


set targetMix to (targetFolder & documentName & ".app")
set SetFileds to targetMix & ":Contents:Resources:droplet.icns" as alias

The command to move and copy a file is duplicate

Ok, thanks Stefank. So, the code are right and it works fine.

I posted all the script, it can be usefull for other user :slight_smile:


-- 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)