Can't get relative location of local files - "path to me as text " not working in Xcode - applescript-objc

I have having real trouble getting the path of objects within my Xcode project - previously in another thread adayzdone suggested to use:
set parentDirectory to POSIX path of ((path to me as text) & "::")
Which works brilliantly... in Applescript Script Editor, but causes this error when included in my Applescriptobjc project in Xcode :
Can’t make «class ocid» id «data optr00000000609B220080600000» into type constant. (error -1700)
Still has me stumped!

I worked it out.
set ImagePath to current application's NSBundle's mainBundle()'s bundlePath() as text & "/Contents/Resources/imageName.png"
Thanks.

Related

g++ is not recognized as an internal or external command Windows 10

First off I would like to say I've seen the previous questions on this site, I've tried every solution but none fit my use case or solves my problem.
I am having trouble with the g++ complier being recognized, I've included this path:
C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
which is where the current version of mingw is located (recently downloaded). I've also tried other options like changing the path to gcc.exe, and just regular bin. Someone please provide a detailed solution to this problem.
Other things i have tried and looked at closely would be:
http://stephencoakley.com/2015/01/21/guide-setting-up-a-simple-c-development-environment-on-windows
seeing as though I'm working through sublime text 3
Another thing Ive tried:
Ive tried to copy and paste the path into cmd and run it , but i find this error code:
C:\Users\Kxrk>C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
So seeing that, i tried another way , and that is to drag the file and drop it into cmd and get this :
C:\Users\Kxrk>C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
g++.exe: fatal error no input files
compilation terminated
when u drag and drop the file it has double quotes around it , so i tried editing the path to contain double quotes around it and the path automaticlly changes back after saving.
This was very simple , it was one of those weird cases.
To solve my problem what i did was:
1: uninstall , the current version of the mingw compiler , because i felt as though the one i had was corrupt in a way.
2:Redownloaded it the compiler from the website http://www.mingw.org/
3: set up the new Environmental variable where i save it , witch was C:\MinGW\bin
I had to install g++ from the command line(cmd ,command prompt)
by using this command mingw-get install g++witch is located inside bin on default
now i created one more directory in the environmental variables , C:\MinGW\bin\g++.exe
6.Now everything works , and is normal
If you are trying to run the compiler from the command line then you have to put double quotes around the path, because the path contains two whitespaces (this is the reason for the first error).
The reason for second error is that you didn't specify which C++ program you want to compile. You have to append the filename of your C++ input file to your command:
C:\Users\Kxrk>"C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe" program.cpp
See Barmak Shemiranis answer if don't want to enter the full path all the time. After that you can just use this:
C:\Users\Kxrk>g++ program.cpp
You have to use quotation marks around the path so that is treated as a single path:
c:\>"c:\program files\path\g++.exe"
A better way is to set the environment variables. Open Environment variables windows (in Windows 10 you can type in "environment variables" in search box) or right click on "Computer" in desktop, open "Advanced System Settings" and find the button for "Environment variables"
Go to your command propmpt, type set path, it will show list of directories, copy them,
Now type set path=<data you copied> and then add a semicolon and possible directory to g++ usually C:\MinGW\bin

Absolute file path in c++ under Linux

I've been trying to access a given file that is always in the same location with the following C++ code:
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("~/Downloads/table_scene_lms400.pcd", *cloud) == -1) //* load the file
Since apparently the "~" is not working under C++, various posts on the internet suggest using /home/Downloads/... instead. I do not however seem to get it to work. I keep getting an error saying that the given file under above path cannot be found.
What is the correct way to access an absolute file path in C++?
Thanks very much, and sorry for the basicness of the question!
Shells such as bash and zsh expand ~ to the home directory. The function you used doesn't. You will have to expand it some other way. You can cd ~ and then pwd to figure out where the shell thinks your home directory is and use that. Alternatively you can launch a shell and ask it for the home directory or try an environment variable or use some library such as Qt: QDir::homePath().
The tilde ~ is expanded by the shell, it's not a universal part of paths.
I suggest you use the environment variable HOME to get the path to the current users home-directory, and then append the rest of the path.
C++ runtime doesn't expand file paths. What I do is something like this:
#include <cstdlib>
std::string const HOME = std::getenv("HOME") ? std::getenv("HOME") : ".";
std::ifstream myfile(HOME + "/path/in/home/folder.txt");

Where would incorrectly named files (rename without specifying the path) be moved to?

I accidentally made a big blunder:
In my C++ program, I did:
std::string oldFilePath = "/Users/blah/somepath/foo.xml";
std::string newFileName = "foo.xml" //Blunder! Forgot to prefix the new path!
int status = rename(oldFilePath.c_str(), newFileName.c_str());
I forgot to prefix the new path, and just put the filename (without a path) for the new name that the file should be renamed to. As a result the file has vanished from the old path, and I don't know where its gone to!
Where is the file ? Is there a way to recover it ? (Time Machine is disabled for this folder, so I can't do that!)
EDIT: Where would the compiled file generated by Xcode for a C++ application be ?
EDIT: If you're running the program through xcode, it should be in:
~/Library/Developer/Xcode/DerivedData//Build/Products/Debug/
Don't forget the ~ in the above path!
If the operation succeeded (status == 0), the file would be in the current directory of the process when it was run. It is hard to predict where that might be, but $HOME is one plausible candidate (maybe /Users/blah/foo.xml). You should be able to find it, either with the find command or with Spotlight.
I don't use the XCode UI (or other IDEs), in part because I don't like the lack of control over things like 'where the program is put' and 'what is the current directory when I run the program' (and for the rest because I'm a dinosaur). AFAIK, the executable should be in a directory underneath the folder where you created the project. Again, Spotlight or find should be able to help you, at least if you chose a distinctive name for the program. The project directory is another place to look for the foo.xml file too.

QDir absolutePath on Mac

Im getting two different paths when i run the same build within Qt Creator and when I double click on it from the Finder on a Mac.
Here is my code:
QDir dir = QDir::currentPath();
dir.cdUp();
dir.cdUp();
dir.cdUp();
QString rootPath = dir.absolutePath();
When I run it (debug) mode in Qt Creator my path is:
/Users/myuser/Projects/AppName/build/mac
When I double click on the file that is located on
/Users/myyser/Projects/AppName/build/mac from finder it returns
/ only.
Why would I get two different paths?
Version: Qt5.2.1
Update
Seems like its a bug from reading the following URLhttp://qt-project.org/forums/viewthread/34019
Why would I get two different paths?
As they write in the thread you linked, QDir::currentPath() does not necessarily returns the application directory. It will return the path from wherever the application is run, which will be different than the application directory when running the application from the command line, or even from "start menu" alike places and so on.
If you wish to deal with the application directory to navigate from there, you would need to use the following method instead:
QString QCoreApplication::applicationDirPath() [static]
Returns the directory that contains the application executable.
For example, if you have installed Qt in the C:\Qt directory, and you run the regexp example, this function will return "C:/Qt/examples/tools/regexp".
On Mac OS X this will point to the directory actually containing the executable, which may be inside of an application bundle (if the application is bundled).
The last sentence even clarifies the Mac OS X case.
The current directory can be anything, it solely depends on how your process is launched. What you've shown so far is that Qt Creator and Finder start the process with different current directory, that's all.
The only use for currentPath without setting it first, that I can think of, is in command line / console applications. Why do you think you need to use it? To what end?

Windows Service failes to start with "Path '.' not found"

Disclaimer: the error message is translated from Swedish (and it's a pain to find the exact corresponding error message in English, Microsoft take note...)
The error message could also be "Path ' ' not found" or "Path not found". It's a bit unclear due to the Swedish message not enclosing the path in ' '.
This is similar to this question, but not exactly: New Windows Service installed, fails to start: "System error 2 ... system cannot find the file specified"
I have written the service myself. It is an exe written in unmanaged C++ and is using the following external code:
libntlm - loaded as dynamic library (libntlm-0.dll placed in same location as executable)
OpenSSL - loaded as static library
pugixml - compiled directly into code
The problem I'm having is that it doesn't start when Windows starts, but it does start if I manually start it!
I am stumped as to what could be wrong. The only thing I can think of is if perhaps the dll can't be found, but I don't know why it wouldn't. Something with the environment variables being different perhaps?
What I have tried:
Checked registry, path is correct
Path is to local disk
Changed to a number of different paths (no change)
Made sure there are no spaces in the path
Logging at start of program (nothing written to log, so it's not an internal path not found error)
Dll is in same path
Set to start with my own network account (no change)
Tried renaming exe to be the same as service name (no change)
Tried registering libntlm-0.dll with regsrv32 but that didn't work
Put libntlm-0.dll in System32 (no change)
For posterity it seems like the delayed start suggested by 51k seems to work. I don't know why that should make any difference, but as long as it works I'm happy.