Monday, November 08, 2010 at 12:02 AM.

system.verbs.builtins.export.sendToDesktop

on sendToDesktop (adrScript, path) {
	<<Create a script that can be double-clicked in the Finder or Explorer.
		<<Old code:
			<<on sendToDesktop (adr, fname) <<create a script that can be double-clicked in the Finder
				<<the contents of a desktop script:
					<<two 'STR ' resources:
						<<127 -- the number of parameters is expects (zero or one)
						<<130 -- the object db address of the script that was exported
					<<one 'scpt' or 'code' resource:
						<<the script that's run when the file is double-clicked on
					<<see Frontier.clickers.type2CLK for the other side of this script
				<<
				<<if not defined (adr^) <<can't export something that doesn't exist
					<<scriptError ("Can't export because there's no object named " + adr + ".")
				<<
				<<bundle <<create the file, save the packed script
					<<local (resdata)
					<<local (type = typeOf (adr^))
					<<Frontier.new2ClickFile (fname)
					<<pack (adr^, @resdata)
					<<rez.putresource (fname, type, 129, @resdata)
					<<rez.putstringresource (fname, 130, adr) <<address of object is a STR resource
					<<
					<<bundle <<save the parameter count -- one or zero
						<<local (params = 0)
						<<if type == scriptType <<scan parameter list
							<<local (scriptheader, savedisplay, savecursor)
							<<scriptheader = string.lower ("on " + nameOf (adr^))
							<<
							<<target.set (adr)
							<<savedisplay = op.getDisplay ()
							<<op.setDisplay (false)
							<<savecursor = op.getCursor ()
							<<op.firstsummit ()
							<<loop <<scan for script header
								<<if not script.isComment () <<skip leading comments
									<<local (s = string.lower (op.getLineText ()))
									<<if (s beginsWith scriptheader) and not (s contains "()")
										<<params = 1
									<<break
								<<if not op.go (down, 1)
									<<break
							<<op.setCursor (savecursor)
							<<op.setDisplay (savedisplay)
							<<target.clear ()
						<<rez.putstringresource (fname, 127, string (params))
				<<
				<<return (true)
				<<
				<<Frontier 5.0d6: Friday, July 18, 1997 at 10:20:45 AM by PBS
				<<Create a script of type 'FATP' that can be double-clicked and run.
				<<local (s = fatPages.buildFileAtts (adr, true))
				<<if sys.os () contains "Win"
					<<fname = fname + ".fatp"
				<<file.writeWholeFile (fname, s, 'FTsc', 'LAND', clock.now ())
				<<return (true)
	if sys.os () beginsWith "Win" { //make sure we have an extension
		if not (string.lower (path) endsWith ".ftds") {
			path = path + ".ftds"}};
	if file.folderFromPath (path) == "" { //only a file name given
		local (desk = file.getSpecialFolderPath ("", "desktop", false));
		path = desk + path};
	local (fatData = fatPages.buildFileAtts (adrScript, true));
	file.writeWholeFile (path, fatData, 'FTds', 'LAND', clock.now ());
	return (true)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.