In the "Run Script" build phase of my project, everything works if I type in the script into the text box for "run script" in build phases.
But to make editing / diffing etc easier, I thought I would save the script as a file as part of my project, and just fill in the path in the text box instead:
Eg: I paste the following path in the text box.
/Users/superman/Documents/Projects/SomeProject/scriptname.sh
But when I try to build this, I get a "Permission Denied" message.
What can I do to fix this? If I cut/paste the actual code, then it just "works". My user account is an administrator account. No one else uses my machine.
You can simplify your Xcode project file a little further and not require the "bin/sh " in front of the script name.
To avoid this, you need to turn on "execute" permissions for users (Xcode in this case) of the file.
Steps
Go into terminal
Navigate to where your script is
run chmod 755 yourScriptName.sh
Put /bin/sh in front of the path to the script name.
/bin/sh /Users/superman/Documents/Projects/SomeProject/scriptname.sh
Just use
chmod u+x nameofscript.sh
Thats it .
Simple Steps:
Go to the <your_Script>.sh via cd <Your_Path_To_.sh_File>
Run chmod +x <your_file>.sh
Thats it
Related
I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali
I want to make a shell script, which is executed when it is clicked on. I know you can do this with the Terminal command chmod u+x (filename) but I want to be able to send the file let's say by email or scp, and it should still be executed when clicked on by the new user.
I don't really think that is possible. The executability of the file is not an attribute within the file which tells the system to execute it. Its something you tell the system to do. I guess it is a security measure, regarding running maybe a risky command, lets say, rm -rf an important system folder.
I'm trying to set up an Applescript as a behavior in Xcode 4, but Xcode won't allow me to select my script. What kind of file is a valid script for Xcode? I've tried .applescript, .scpt, and .txt. I've also tried no extension at all.
What do I need to do?
This is what I get for neglecting to read the documentation on creating a new behavior. (iOS developer login required.)
It turns out that Xcode can accept an executable file as a script. The solution was to run chmod +x on the script file and then Xcode allowed me to select it. It's funny, because I wasn't aware that Finder allowed filtering based on chmod permissions.
While it appears you are looking specifically for AppleScript, shell files are valid for behavior scripts.
Create a new .sh file:
#!/bin/sh
#here is some code!
Make sure it is executable:
chmod +x <my file name>.sh
Assign it as the run script. That should be all you need to do.
I have a question I have been trying to fix for a while. I want to understand what's the difference between starting a script from the command line and making it executable and then running it from the Finder.
Because this is what I am experiencing;
I have a simple script called trash-files which contains this command:
trash ~/Downloads/*
When I run from the terminal it works as expected; however if I doubleclick the shell script in the finder I see this:
/Users/xx/Desktop/trash-files: line 1: trash: command not found
I hope anyone can tell me why this doesn't work as expected
trash is not a standard command in OS X. Is it something defined in your ~/.profile or a similar file? If so, these are not run for non-login shells, such as those created to run a script.
If you're using homebrew, you could run
brew install trash
which would install the necessary scripts to have the trash command work in the way you're expecting.
There is a folder in your home folder location called
.Trash
The "dot" in front of the folder name makes it hidden while searching for it in finder. You'll have to use Terminal to execute the following command:
cd ~/
ls -la
This will change the directory to the current logged in users home folder, then second command will list files and show hidden files. You can then run:
rm .Trash/*
This will remove everything inside the Trashcan on the dock.
So open TextEdit from the /Applications folder, go to "Format" and make it "Plain Text". Paste in the two lines below.
#!/bin/sh
rm ~/.Trash/*
Save the file as "emptyTrash.sh" (uncheck use txt extension). Save it to your Desktop or wherever you'd like. Then open Terminal, cd (change directory) to where the files is and run this command to make the script executable:
chmod +x emptyTrash.sh
Then you can execute the script by cd (changing directory) to path where the script is, and run:
./emptyTrash.sh
That's it.
Here is what I get when I try to build my Xcode project:
Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh
/Users/ssbarnea/Library/Developer/Xcode/DerivedData/demo2-fdzrmxojwtekcbeivraccjjadvqz/Build/Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh: line 2: ${PROJECT_DIR}/local-deploy.sh: No such file or directory
In Xcode I added to the default arget a new Build Phase, a "Run Script" that runs with shell /bin/sh and contains only:
'${PROJECT_DIR}/local-deploy.sh'
I can assure you that the local-deploy.sh file exists in the project directory and that it is executable. It even works if I call it from the console ;)
It should be the following. s/'/"/g :-)
"${PROJECT_DIR}/local-deploy.sh"
Bourne Shell Tutorial - Strong versus weak quoting
Well, I don't think that replacing this will work. You need just put OpenCV.framework folder in proper project folder and I think that is it. I tried out and it worked.