Page 1 of 2

Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Feb 28, 2014 7:52 pm
by Mag
I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac... :oops:

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Feb 28, 2014 8:31 pm
by Thierry
Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
Yes, it's possible!

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Mon Mar 03, 2014 8:24 am
by Thierry
Hello Mag,

I'm wandering if my last post was enough :)
I made it few seconds before running out of my office on Friday evening...

That said, here are some shell commands which should help you:

- halt // shutdown immediately
- reboot // restart immediately
- shutdown -h +15 // in 15 mn
- shutdown -h 22:22 // at a secific time
- shutdown -r now // reboot immediately
- shutdown -h now // shutdown immediately
- etc.

All these commands can be executed by the Livecode shell() function.
You need the sudo command as a prefix to these commands
and it will ask for your password.

Unfortunately,you can't do that only via the LC shell()
as it opens a non-interactive shell process underneath.

There, expect comes to the rescue again:

Code: Select all

      get "expect -d -c" & quote &cr& \ 
                  "set timeout 1" &cr& \ 
                  "spawn sudo cp /Users/t/x.txt /"  &cr& \ 
                  "expect Password: { send 42cheese\r\n }" &cr& \ 
                  "expect eof" &cr& \ 
                  "sleep 1" &cr& \ 
                  "exit" & quote 
      get shell( IT)
   -- verify:
      put "shell: " & IT &cr& the result &cr& shell("ls -alst /x.*")
By the way, there is a book of 640 pages:
http://shop.oreilly.com/product/9781565920903.do

Be well,

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Mon Mar 03, 2014 12:56 pm
by Klaus
Thierry wrote:I'm wondering if my last post was enough :)
Well, I found it quite amusing :D

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Mon Mar 03, 2014 2:13 pm
by Mag
Wow, wonderful post Thierry! :lol: :D

THANK YOU

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Mon Mar 03, 2014 2:25 pm
by Thierry
Klaus wrote:
Thierry wrote:I'm wondering if my last post was enough :)
Well, I found it quite amusing :D
So, I'm a happy chap if you smiled :)

Best,

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Mon Mar 03, 2014 2:31 pm
by Thierry
Mag wrote:Wow, wonderful post Thierry!
THANK YOU
You're welcome.

Umm, don't recognize myself in the picture.
You know, I've almost no more hair left, plus a white beard..

Regards,

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Thu Apr 17, 2014 6:57 pm
by EssoAir
Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac... :oops:
Wouldn't it be easier to do in AppleScript?

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Thu Apr 17, 2014 8:23 pm
by Mag
EssoAir wrote:
Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac... :oops:
Wouldn't it be easier to do in AppleScript?
Hi EssoAir, thank you for your post, at the end I done it with AppleScript. 8)

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 8:12 am
by Thierry
EssoAir wrote:
Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac... :oops:
Wouldn't it be easier to do in AppleScript?
Depends of your backgroung and knowledge, no?
And then Applescript is for Mac only!
Mag wrote:Hi EssoAir, thank you for your post, at the end I done it with AppleScript. 8)
Any chance to show us how you do it?

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 8:55 am
by Mag
Hi Thierry,

With pleasure! Here is a sample stack.

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 9:56 am
by Thierry
Mag wrote:Hi Thierry,

With pleasure! Here is a sample stack.
Thanks Mag.

So, learning the finder's applescript dictionnary might be useful :)

Regards,

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 10:50 am
by Mag
Hi Thierry,

Yes, and a lot of other applications... Some other samples...

Code: Select all

tell application "System Events"
    log out
end tell

Code: Select all

tell application "Finder"
    sleep
end tell
Some time ago, I made simple-sample stack for iTunes, you can find here:

http://forums.runrev.com/viewtopic.php? ... 128#p97918

And here I posted a Send Email with Mail sample:

http://forums.runrev.com/viewtopic.php? ... 48#p100224

The only problem is that if you plan to deploy the app in the Mac App Store is unlikely to be accepted because of the violation of the Sandbox.

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 11:03 am
by Thierry
Mag wrote:

Code: Select all

tell application "System Events" to log out

tell application "Finder" to  sleep
Umm, so for shutdown and sleep it's the Finder
and for log out, it's the system events..

Doesn't sound that easy for me :)
The only problem is that if you plan to deploy the app in the Mac App Store is unlikely to be accepted because of the violation of the Sandbox.
Well, it's the same with the shell then.
I think I've read we can use applescript in a sandbox app only to get information...
Is that true?

Regards,

Thierry

Re: Using LiveCode to shutdown, logout and restart the Mac

Posted: Fri Apr 18, 2014 1:19 pm
by Mag
Hi Thierry, Database Events, Image Events, and System Events are applications that can be used by AppleScript and that run invisibly to users, every one has it's dictionary you can see them with the Applescript Editor.

The sandboxing imposes restrictions on what the application can do, I think that there si no a simple rule and the approval process perhaps it depends on who reviews the app. It may be helpful to read about the cases reported by the developers. Maybe what you say may be right. I have no experience about for now. If you find something useful to us let us know.