Using LiveCode to shutdown, logout and restart the Mac
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Using LiveCode to shutdown, logout and restart the Mac
I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
Re: Using LiveCode to shutdown, logout and restart the Mac
Yes, it's possible!Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
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:
By the way, there is a book of 640 pages:
http://shop.oreilly.com/product/9781565920903.do
Be well,
Thierry
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.*")
http://shop.oreilly.com/product/9781565920903.do
Be well,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
Well, I found it quite amusingThierry wrote:I'm wondering if my last post was enough
Re: Using LiveCode to shutdown, logout and restart the Mac
Wow, wonderful post Thierry!
THANK YOU
THANK YOU
- Attachments
-
- images.jpeg (15.6 KiB) Viewed 12099 times
Re: Using LiveCode to shutdown, logout and restart the Mac
So, I'm a happy chap if you smiledKlaus wrote:Well, I found it quite amusingThierry wrote:I'm wondering if my last post was enough
Best,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
You're welcome.Mag wrote:Wow, wonderful post Thierry!
THANK YOU
Umm, don't recognize myself in the picture.
You know, I've almost no more hair left, plus a white beard..
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
Wouldn't it be easier to do in AppleScript?Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
Re: Using LiveCode to shutdown, logout and restart the Mac
Hi EssoAir, thank you for your post, at the end I done it with AppleScript.EssoAir wrote:Wouldn't it be easier to do in AppleScript?Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
Re: Using LiveCode to shutdown, logout and restart the Mac
Depends of your backgroung and knowledge, no?EssoAir wrote:Wouldn't it be easier to do in AppleScript?Mag wrote:I wonder if it is possible to use LiveCode to perform operations as log out, restart and shut down your Mac...
And then Applescript is for Mac only!
Any chance to show us how you do it?Mag wrote:Hi EssoAir, thank you for your post, at the end I done it with AppleScript.
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
Hi Thierry,
With pleasure! Here is a sample stack.
With pleasure! Here is a sample stack.
- Attachments
-
- ShutDownComputer.livecode.zip
- (1.06 KiB) Downloaded 267 times
Re: Using LiveCode to shutdown, logout and restart the Mac
Thanks Mag.Mag wrote:Hi Thierry,
With pleasure! Here is a sample stack.
So, learning the finder's applescript dictionnary might be useful
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
Hi Thierry,
Yes, and a lot of other applications... Some other samples...
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.
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
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
Umm, so for shutdown and sleep it's the FinderMag wrote:Code: Select all
tell application "System Events" to log out tell application "Finder" to sleep
and for log out, it's the system events..
Doesn't sound that easy for me
Well, it's the same with the shell then.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.
I think I've read we can use applescript in a sandbox app only to get information...
Is that true?
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Using LiveCode to shutdown, logout and restart the Mac
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.
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.