• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: drapplet?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drapplet?


  • Subject: Re: drapplet?
  • From: "S. J. Cunningham" <email@hidden>
  • Date: Wed, 25 Jan 2017 20:31:11 -0500


On Jan 25, 2017, at 5:51 PM, Mitchell L Model wrote:

I rarely make script apps, so this may be a really naive question. Is it widely (at all?) recognized that you can have a script app that can be run either by double-clicking or by dragging files over it? A "drapplet"? As follows:

-- Demonstration of a "drapplet": 
-- a script that can be run either by double-clicking
-- or by dragging files over its icon
--
-- Mitchell L Model, email@hidden, 2017-01-25

on run argv
display alert "Double-clicked or run from editor"
-- I don't know how to tell the difference
end run

on open args
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return & return}
try
display alert "Files dropped:" & return & return & (args as text)
end try
set AppleScript's text item delimiters to oldDelimiters
end open

Here is a template I use that allows you to use the same code whether it is dropped or run:

(*
This technique allows you to differentiate whether the main
routine was entered by a drop or by a direct open. *)

property p_Open : false
global g_OpenArgList

on open (aList)
global g_OpenArgList


set g_OpenArgList to aList
set p_Open to true
run
end open

on run
if p_Open then
set p_Open to false
set aList to g_OpenArgList
set theSender to "open"
else
set aList to {1, 2, 3}
set theSender to "run"
end if


display dialog "aList from \"" & theSender & "\": " & aList as string with title "Main Routine"


end run




Steve
------------------
OS X 10.6.8, AppleScript 2.1.2

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: drapplet?
      • From: Shane Stanley <email@hidden>
References: 
 >drapplet? (From: Mitchell L Model <email@hidden>)

  • Prev by Date: An Acrobat Pro heads up.
  • Next by Date: Re: An Acrobat Pro heads up.
  • Previous by thread: Re: drapplet?
  • Next by thread: Re: drapplet?
  • Index(es):
    • Date
    • Thread