• 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: AppleScript After Launchd Job
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript After Launchd Job


  • Subject: Re: AppleScript After Launchd Job
  • From: Pierce Freeman <email@hidden>
  • Date: Sun, 07 Jun 2009 10:01:32 -0700
  • Thread-topic: AppleScript After Launchd Job

Just one more question though, how would I go about making multiple line
codes in the launchd file?  And how do you deal with quotes?


On 6/7/09 2:29 AM, "Philip Aker" <email@hidden> wrote:

> On 2009-06-06, at 15:57:47, Pierce Freeman wrote:
>
>> Just one question, though, which is how I can use cp in that same
>> way to copy a file from one directory into the other.  Your echo
>> example works fine, but I just can¹t figure out how to move it.
>
> Based on the fact that you can't figure that out but already gave the
> correct form in your "ProgramArguments", I suggest that a power hour
> with a unix shell scripting tutorial will pay bigger dividends than a
> direct answer. As to which tutorial is the best, I can't say because
> it's a matter of finding an author you can relate to rather than any
> other criteria. That is, if the first one you read doesn't appeal
> after a few pages, move on to another choice. A search such as:
> <http://www.google.com/search?q=unix+shell+script+tutorial
>> gives wide range of possibilities and the man page for cp on Mac OS
> X is at <x-man-page://cp>.
>
>
>>>> My salient part of my code is below:
>>>
>>>> <dict>
>>>>     <key>Program</key>
>>>>     <string>bin/cp</string>
>>>
>>>>    // What do I put for the AppleScript?
>>>>     <key>ProgramArguments</key>
>>>>     <array>
>>>>         <string>cp</string>
>>>>         <string>-Rf</string>
>>>>         <string>Location</string>
>>>>         <string>Location</string>
>>>>     </array>
>>>> // What do I put for the AppleScript?
>>>> </dict>
>>>> </plist>
>>>
>>>> I added comments for where I think the AppleScript should go,
>>>> though I may be very wrong about it. ;)
>>>
>>> Close but no cigar.
>>>
>>> - Firstly the form of the value for 'Program' should probably be a
>>> full path.
>>>
>>> - Secondly, you have to use controller shell, like sh, bash, or
>>> tclsh, etc., to be able to call multiple tools. For such shells,
>>> usually the option specifying an inline script implies that the
>>> subsequent arguments are directed to that script. Hence a one line
>>> script is used in the case no arguments are needed.
>>>
>>> Here something that works for me as a startup script (I'm using
>>> 10.5.7).
>>> It's a LaunchAgent plist named 'ca.aker.startup.plist' (to
>>> coordinate with the 'Label' value) and placed in ~/Library/
>>> LaunchAgents.
>>> I use the 'WorkingDirectory' key to have launchd cd to wherever and
>>> then run my script.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
>>> "http://www.apple.com/DTDs/PropertyList-1.0.dtd
>>> ">
>>> <plist version="1.0">
>>> <dict>
>>> <key>Label</key>
>>> <string>ca.aker.startup</string>
>>> <key>Program</key>
>>> <string>/bin/sh</string>
>>> <key>ProgramArguments</key>
>>> <array>
>>> <string>sh</string>
>>> <string>-c</string>
>>> <string>echo `date +&apos;%F %T&apos;` &gt; date.txt;/usr/bin/
>>> osascript -e &apos;tell application &quot;TextEdit&quot; to
>>> activate&apos;</string>
>>> </array>
>>> <key>RunAtLoad</key>
>>> <true/>
>>> <key>WorkingDirectory</key>
>>> <string>/Users/me/Desktop</string>
>>> </dict>
>>> </plist>
>>>
>>>
>>>
>>>>>> Thanks for your reply.  However, I am including the actual code
>>>>>> in the
>>>>>> Launchd file (I know, I know) so how would this translate into
>>>>>> that
>>>>>> scenario?  I get what you are saying, however I am just not seeing
>>>>>> how that
>>>>>> could be translated into Launchd.
>>>
>>>>> Maybe you'd better show the salient part of the LaunchAgent plist.
>>>>> Inline scripts work kinda like NSTask.
>>>>> One non-obvious part about shell scripts in that format is that
>>>>> they
>>>>> have to be XML escaped.
>>>>> Otherwise, it's just the same as the single line example but you
>>>>> would
>>>>> use the -e option for osascript.
>>>
>>>>>>>> I am making a Launchd job, and want to run an AppleScript once
>>>>>>>> it is
>>>>>>>> done
>>>>>>>> with it's main task.  I want my cd job to run, and then a
>>>>>>>> follow-up
>>>>>>>> AppleScript to run afterwards.  My problem is that I don't
>>>>>>>> know how
>>>>>>>> to use
>>>>>>>> two different "main codes" (ex. cd) to be run in one launchd.
>>>>>>>
>>>>>
>>>>>>> I'm guessing you would want something like the following in your
>>>>>>> shell
>>>>>>> script:
>>>>>>>
>>>>>
>>>>>>> cd /path/to/dir;
>>>>>>> osascript /path/to/some.scpt;
>>>>>>>
>>>>>
>>>>>>> To run multiple shell script calls from a single line it would
>>>>>>> be:
>>>>>>>
>>>>>
>>>>>>> cd /path/to/dir;osascript /path/to/some.scpt;
>>>>>>>
>>>>>
>>>>>>> The basic command separator is a semicolon.
>
> Philip Aker
> echo email@hidden@nl | tr a-z@. p-za-o.@
>
> Democracy: Two wolves and a sheep voting on lunch.
>


 _______________________________________________
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: AppleScript After Launchd Job
      • From: Philip Aker <email@hidden>
References: 
 >Re: AppleScript After Launchd Job (From: Philip Aker <email@hidden>)

  • Prev by Date: Re: AppleScript After Launchd Job
  • Next by Date: Re: Xcode and text field
  • Previous by thread: Re: AppleScript After Launchd Job
  • Next by thread: Re: AppleScript After Launchd Job
  • Index(es):
    • Date
    • Thread