Running a terminal command in xcode

Hey guy and gals
I had a question for the xcode experts out there. I'm new to using xcode and to objective c. The problem I'm having is I'm trying to tell my program to run a code that terminal uses. Of course xcode throws back errors. How do I tell xcode to run the terminal syntax code so that I can get this program running?
Thanks
James

I started with a Cocoa App. Let me try and explain what I'm trying to do. It might shed some light on my problem. I'm trying to write a program that runs this code with a click of a button.
defaults write com.apple.finder AppleShowAllFiles TRUE

killall Finder
normally I open up a terminal and run the code. Works great. Well my wife is in the hospital with preeclampsia and I'm not leaving her side. since she is here till our son is born or if she can make it to 34 weeks so the doctors can induce. shes at 31 weeks 4 days.
anyways I decided to give myself something to do while we sit around all day. shes not aloud tv do to the risk of seizures. So i thought to myself why don't i try to write a program that when i click the button it will run the code automatically and then when im done reverse it. Since i dont want my hidden files shown all the time. So I'm trying to tell xcode to run this code in the background and display hidden files then when I click hide hide the hidden files.

Similar Messages

  • #30 | can i run the Terminal Command to stop Snapshots with no problems?

    i am somewhat surprised to find out that the 75 GB of "Backups" that are taking up space on my MBP may be due to some "feature" in Mavericks or the new OS's or whatever and i have had to MOVE all my data off my laptop as a consequence of this over the last two months because i have no more space on my Hard Drive.
    is it legit and OK to follow the terminal commands in #30 without having any problems?
    i am on a mid 2009 MBP running Mavericks and i have a 2 TB Time Capsule that i am wirelessly backing up my data.
    as some kind of sadistic test in advance of running this terminal command - can i plug my laptop into the Time Capsule, unplug the laptop from the time capsule, restart and see how much space got recaptured on my HD for my data?
    i mean, well - i must be missing something but i mean i am hoping i can get this to stop so i can get my data back on my laptop. i'm walking around with an external HD of all my Mac Pro information just so i can get work done when i go to a coffee shop or something.

    for those suffering through this:
    https://discussions.apple.com/message/24878591#24878591
    In Terminal:
         sudo tmutil disablelocal
    Turn off local Time Machine snapshots and trigger automatic cleanup of accumulated local snapshot data. Requires root privileges.
    (use sudo tmutil enablelocal to turn back on)
    this got rid of my 75 GB backup file (!!) and now i am going to move my data back to my laptop...
    not sure if there is an apple tech article to link to regarding this issue but it would be good to post if there is one.

  • How to run Terminal commands in Xcode?

    Anyone knows how to include Terminal commands ( like sudo) in Xcode?  for example in a line of my program I need to run this:
    sudo open/Library/Preferences/com.apple.sharing.firewall.plist
    I searched the library but found no class or routine for that.

    Well, I am not a professional programmer, but one of the things I continue to learn is how to wade through all of the Cocoa documentation (and it does get deep in spots).  Chances are though, no matter what you are trying to do, Apple or some third party has created a class to make it easier - you just have to find it.  My Xcode documentation bookmarks continue to grow, but you might start with some of Apple's documentation, such as
    Cocoa Fundamentals Guide
    Foundation Framework Reference
    Application Kit Framework Reference

  • How do I run a terminal command from a dashboard icon

    Hello
    I run the following terminal command repetitively and would like to simplify by running from an icon on the dashboard.
    sudo killall coreaudiod
    Thanks
    John

    Look at creating a simple AppleScript app using the "do shell script with administrator privileges".  Google can help if you use that search string.
    <http://www.maclife.com/article/howtos/how_authenticate_applescripts_administrato r_privileges>
    Applications -> Utilities -> AppleScript Editor
    do shell script "killall coreaudiod" with administrator privileges
    Save as an AppleScript Application and put the application in your Dock.  That should be just as easy to launch as using a dashboard widget.

  • Running Terminal Commands at Login

    Hi everyone!
    Just a quick question for anyone who may know the answer. I am trying to automatically run two terminal commands at login:
    sudo pmset -a halfdim 0
    sudo pmset -a halfdim 1
    I have absolutely no idea what I am doing, so if someone knows and can help me out, that would be great! Thanks a lot!
    ~ Philip

    Trying to make the screen wink at you when you login?
    You could install Platypus and create a little shell script with it and put it in your Login items. The script would be something like
    <pre class=command>sleep 30; sudo pmset -a halfdim 0; sleep 0.2; sudo pmset -a halfdim 1</pre>
    Those sleeps should be tweaked for the best effect. If sudo prompts you for a password, then it won't work.
    Message was edited by: jarik
    Hey man, check out the day we registered here!

  • Applescript to run terminal command then open application..

    Hey,
    I've installed the add-on to make the Lion Finder sidebar icons colored again, but whenever I reboot my Mac, I have to execute a killall Finder to get those icons back. This also closes TotalFinder, which is an addon I use. So, I want to write an AppleScript which will run on startup, and do those two things: run the Terminal command, and then open TotalFinder.
    I've written:
    tell application "Terminal"
        activate
        do script "killall Finder" in front window
        quit
    end tell
    tell application "TotalFinder"
        activate
    end tell
    This gives me an error stating "Connection is invalid." when running the activate line for TotalFinder. The Terminal command is executed correctly. Any idea why this is? The application is definitely named correctly, its just in my root Applications directory so it should be able to find it, etc. How can I get this working?
    Thanks!

    try this:
    do shell script "killall Finder"
    tell application "TotalFinder"
              try
      activate
              end try
    end tell
    First thing you don't need to open a terminal window to do the killall you can just do to as a shell script.
    Second don't know why TotalFinder gives that message about Connection invalid but it doesn;t seem to affect it any. So putting in the try just eats the error message.
    Ypu may not even need the killall, When TotalFinder starts it restarts the Finder so you may be able to remove the killall
    regards

  • How to make Apple Script do a terminal command

    Hey,
    I am wondering how can I make an AppleScript do the following command :
    "networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4"
    Please mention step by step since I'm new to AppleScript
    Best Regards,
    Nadav.

    To run a terminal command it is usually sufficient to use do shell script. So for your command it would be
    do shell script "networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4"
    note if the command requires administrator privileges you would need to do
    do shell script "command"  with administrator privileges
    will prompt for the password when the script is run.
    do shell script "command" user name "me" password "mypassword" with administrator privileges
    will store the password and username in the script. More convenient but much less secure.
    See do shell script in AppleScript

  • Trying to automate a Terminal command with a password

    Hi,
    I'm a long time Mac user, but not a Terminal expert.
    I've come upon a simple hack that enables me to run two instances of Skype simultaneously. This enables me to use it with two different user names.
    The idea is to create another user on the computer and run the other Skype like this:
    sudo -u user "/Applications/Skype.app/Contents/MacOS/Skype"
    In order to simplify this for daily use, I'd like to create a small applet which runs this terminal command.
    Trying to do so with Automator's +Run Shell Script+ fails with an execution error, probably due to the fact that this sudo command requires an admin password.
    Is there any way to accomplish this?
    Thanks

    hmm... I'm afraid that didn't do the trick. It now opens the Terminal window and launches Skype with the message "another copy of Skype is already running".
    Maybe I should add another step to workflow instead?
    Thanks again, I really appreciate your help.
    Guy

  • How to execute a Terminal command on startup?

    Greetings!
    Is it possible to automatically run a Terminal command at startup? (Specifically - a hwprefs command.)
    If so, could you please detail the steps involved?
    Many thanks!

    OK, then, that's pretty straight forward. You can write a small AppleScript like so:
    set mystring to do shell script "Insert Command String Here" with administrator privileges
    If you need to run the command with root permission then insert "sudo" before the command line, i.e., "sudo commandline". You will need to authenticate in this case so add "with adminstrator privileges" after the command string, i.e.,
    do shell script "sudo command string" with administrator privileges
    Compile the script as a run-only application then add the compiled script to your Login Items (Accounts preference pane.)
    Note that your command line will need the fully qualified path to the command.

  • Parallels, Terminal Command & lost Memory

    Recently Bought Parallels Desktop Running MacPro with 4Meg Ram
    Riser A 512,512,1G,1G
    RiserB 512,512,0,0
    Application will not run with more than 3.5 megs installed but noticed in the Offical Blog http://parallelsvirtualization.blogspot.com/
    a workaround where you can run a terminal command
    sudo nvram boot-args="maxmem=3500"
    And get the app to work.
    It does.
    System profiler now says I only have 3.42 Megs of Ram.
    The blog also says to return your Computer back to recognize all installed memory.
    Run Terminal again: sudo nvram boot-args="maxmem=YOURMEMORYTOTAL"
    MemoryTotal is 4000
    Computer will not acknowledge a certain pair of Apple 512 Dimms regardless of which riser or slot I install them.
    Also zapped Pram
    Have I fried them??
    In way over my head.
    Thanks for any input
    MacPro 2X2.66 Dual Core Intel   Mac OS X (10.4.7)   4Meg Ram 667 DDR2 FB-DIMM
    MacPro 2X2.66 Dual Core Intel   Mac OS X (10.4.7)   4Meg Ram 667 DDR2 FB-DIMM

    Thanks again. Took your advice moved 2X1Gigs to Riser A.
    4X 512 to Riser B.
    No luck with this or new Terminal command.
    Played with different configurations on Riser B
    Original 512 Dimms and Purchased 512 Dimms.
    I'm begining to think it's one Dimm that's the problem not a pair.
    I think I'm just going to have to have it serviced.
    Best

  • Strange terminal command caching while manually running SWUPD.

    I've built dozens of software update servers with little issues. This one has me stumped today.
    I built a software update server to update solely our Tiger machines. Initially, I had sent a command to the clients that hit the wrong IP address. Once I realized the mistake, I overwrote the plist files on them to reflect the correct address.
    Problem is, some of those machines, even tho I have thrown out the plist completely, still seem to be trying to update with the wrong address. I have verified 100 times that the plist is correct. And if I do a softwareupdate -l, it hits the correct address. When I send a softwareupdate -i -a, it gives me this error:
    2010-06-29 13:50:50.606 softwareupdate[728] Loading CatalogURL 10.192.170.11:8088
    2010-06-29 13:50:50.625 softwareupdate[728] loader:didFailWithError:NSError "unsupported URL" Domain=NSURLErrorDomain Code=-1002 UserInfo={
    NSErrorFailingURLKey = 10.192.170.11:8088;
    NSErrorFailingURLStringKey = "10.192.170.11:8088";
    NSLocalizedDescription = "unsupported URL";
    Error: unsupported URL
    Software Update Tool
    The IP address it's reflecting is the original bad address. I'm thinking this has to be cached somewhere, but I've tried it via ARD on fresh machines that had never tried to push any of these commands, and I get the same thing.
    I verified that this happens locally in the terminal and via ARD. But if you manually run the software update from the GUI, it goes to the right place and updates fine.

    No, this is a Tiger server, updating Tiger clients. We literally update the plist via command line or ARD, and then run the softwareupdate -i -a command.
    I have deleted all profile softwareupdate plists via root. It worked on one machine, but not the others. What's odd is that even if i run the software update command locally in the terminal, I still get this error, but if I run it from the Apple menu, it hits the right server and works just fine. So the plist is correct. So I'm wondering what's the difference between where the GUI grabs the address from, and where the terminal command gets it.

  • TS3002 My macbook pro 4,1 runs os x 10.6 but won't run my apple usb superdrive. One forum said that this is due to os x, not hardware. The terminal commands given were for Lion, but don't work in snow leopard. Help!

    My macbook pro 4,1 runs os x 10.6 but won't run my apple usb superdrive. One forum said that this is due to os x, not hardware. The terminal commands given were for Lion, but don't work in snow leopard. Help!

    I was able to get it to work!

  • Desktop runs some weird Terminal Commands and acts like an Application.

    So, My Desktop runs like an application and does a weird terminal command.
    What I can't do:
    Can't copy or place anything on the desktop except for the screenshots I take
    Can't create a new folder
    Can't do anything basically.
    Help?

    Run Disk Utility and Repair Permissions.

  • Is there any Terminal Command that will test how my RAM is running?

    Does anyone know how I can test my RAM efficiency? Because i just upgraded my MacBook Pro 13 inch (Mid 2009) from 4GB of RAM to 8GB of RAM and I'm not really telling any difference..

    Without knowing what you do, what software is running concurrently, I can't say. But here's some things that may help you. They are a little technical:
    About OS X Memory Management and Usage
    Using Activity Monitor to read System Memory & determine how much RAM is used
    Memory Management in Mac OS X
    Performance Guidelines- Memory Management in Mac OS X
    A detailed look at memory usage in OS X
    Understanding top output in the Terminal
    The amount of available RAM for applications is the sum of Free RAM and Inactive RAM. This will change as applications are opened and closed or change from active to inactive status. The Swap figure represents an estimate of the total amount of swap space required for VM if used, but does not necessarily indicate the actual size of the existing swap file. If you are really in need of more RAM that would be indicated by how frequently the system uses VM. If you open the Terminal and run the top command at the prompt you will find information reported on Pageins () and Pageouts (). Pageouts () is the important figure. If the value in the parentheses is 0 (zero) then OS X is not making instantaneous use of VM which means you have adequate physical RAM for the system with the applications you have loaded. If the figure in parentheses is running positive and your hard drive is constantly being used (thrashing) then you need more physical RAM.

  • I would like to know some fun and helpful Terminal commands.

    I would like to know some fun and helpful Terminal commands. So, if you know of any, contact me!
         Thanks
         - Max

    Max,
    if you’ve installed the Xcode compiler and its “command line tools” add-on, there’s a lot of text-mode games for which source code can be downloaded and compiled. Back in the Neolithic Age when I was at university, Empire was a multiplayer favorite (see here for one of its current offspring, which can run multiplayer over the Internet, and for which a text-mode client is still available), and Rogue was popular for when solitary play was the only available option.

Maybe you are looking for