I am working on an ipad project that requires changing the formatting of image names for the project in a run script build phase in xcode 5. I am running the following script:
for f in ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/*.png
do
fileName=${f:${#BUILT_PRODUCTS_DIR}+${#FULL_PRODUCT_NAME}+2:${#f}}
lc='echo $fileName | tr "[:upper:]" "[:lower:]"
lc=`echo $lc | tr - _`
lc=${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/${lc}
mv $f $lc
done
The script finds all images in the bundle and makes the names all lowercase and changes uses of '-' to '_'. This works perfectly for my situation, however it is also changing the name of the app icon and launch images resulting in them not being used by the app.
What I want is either a way to have the script skip the app icon and launch images, or a way to simply change the names of the images in xcode so that the resulting name from the script is the accurate name.
The biggest issue I have had with simply manually changing the names is that I cannot find how xcode is controlling the naming system because the names I have for the images are already in the proper format so xcode must be creating its own names for the icon and launch images.
Thanks
Assuming standard naming, and that you don't also have your own files that begin with "Icon" or "Default", you could do this. If you have your own images that match that pattern, you will need to add special cases below, or specifically target all the various icon and launch image files.
for f in ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/*.png
do
BASENAME=$(basename $f)
if [[ ${BASENAME} == Icon* ]] || [[ ${BASENAME} == Default* ]] ;
then
echo "App icon or launch image, leaving file alone"
else
fileName=${f:${#BUILT_PRODUCTS_DIR}+${#FULL_PRODUCT_NAME}+2:${#f}}
lc=`echo $fileName | tr "[:upper:]" "[:lower:]"`
lc=`echo $lc | tr - _`
lc=${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/${lc}
mv "$f" "$lc"
fi
done
Related
In my Docusaurus project my internal links work on my local environment, but when I push to GitLab they no longer work. Instead of replacing the original doc title with the new one it adds it to the url at the end ('https://username.io/test-site/docs/overview/add-a-category.html'). I looked over my config file, but I do not understand why this is happening.
I tried updating the id in the front matter for the page, and making sure it matches the id in the sidebars.json file. I have also added customDocsPath and set it to 'docs/' in the config file, though that is supposed to be the default.
---
id: "process-designer-overview"
title: "Process Designer Overview"
sidebar_label: "Overview"
---
# Process Designer
The Process Designer is a collaborative business process modeling and
design workspace for the business processes, scenarios, roles and tasks
that make up governed data processes.
Use the Process Designer to:
- [Add a Category](add-a-category.html)
- [Add a Process or Scenario](Add%20a%20Process%20or%20Scenario.html)
- [Edit a Process or Scenario](Edit%20a%20Process%20or%20Scenario.html)
I updated the add a category link in parenthesis to an md extension, but that broke the link on my local and it still didn't work on GitLab. I would expect that when a user clicks on the link it would replace the doc title in the url with the new doc title ('https://username.gitlab.io/docs/add-a-category.html') but instead it just tacks it on to the end ('https://username.gitlab.io/docs/process-designer-overview/add-a-category.html') and so the link is broken as that is not where the doc is located.
There were several issues with my links. First, I converted these files from html to markdown using Pandoc and did not add front matter - relying instead on the file name to connect my files to the sidebars. This was fine, except almost all of the file names had spaces in them, which you can see in my code example above. This was causing real issues, so I found a Bash script to replace all of the spaces in my file names with underscores, but now all of my links were broken. I updated all of the links in my files with a search and replace in my code editor, replacing "%20" with "_". I also needed to replace the ".html" extension with ".md" or my project would no longer work locally. Again, I did this with a search and replace in my code editor.
Finally, I ended up adding the front matter because otherwise my sidebar titles were all covered in underscores. Since I was working with 90 files, I didn't want to do this manually. I looked for a while and found a great gist by thebearJew and adjusted it so that it would take the file name and add it as the id, and the first heading and add it as the title and sidebar_label, since as it happens that works for our project. Here is the Bash script I found online to convert the spaces in my file names to underscores if interested:
find $1 -name "* *.md" -type f -print0 | \
while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done
Here is the script I ended up with if anyone else has a similar setup and doesn't want to update a huge amount of files with front matter:
# Given a file path as an argument
# 1. get the file name
# 2. prepend template string to the top of the source file
# 3. resave original source file
# command: find . -name "*.md" -print0 | xargs -0 -I file ./prepend.sh file
filepath="$1"
file_name=$("basename" -a "$filepath")
# Getting the file name (title)
md='.md'
title=${file_name%$md}
heading=$(grep -r "^# \b" ~/Documents/docs/$title.md)
heading1=${heading#*\#}
# Prepend front-matter to files
TEMPLATE="---
id: $title
title: $heading1
sidebar_label: $heading1
---
"
echo "$TEMPLATE" | cat - "$filepath" > temp && mv temp "$filepath"
I'm relatively new to scripting and using application such as Automator. I would like to try create a script which detects when new images are added to a folder, prints them twice to a device (HP Sprocket) by using the "send file to device" option in Bluetooth, and then moves that image to another folder once the print has been sent (in queue) or completed.
I have used automator to create the transfer of the file, however I have no idea how to go about doing the printing aspect of this. Should I be using applescripts in automator? or another program?
Just for clarification regarding this, this is where the option sits when doing it manually.
The reason I am doing it this way and not just through a standard print is because the HP Sprocket doesn't work as a printer on any devices other than mobile, however you are able to send a file to the device this way with it still printing.
Here are some bits of help:
To detect when files arrive in a folder, you need to Google "Applescript folder actions".
I did something similar to what you are trying and used a folder in Dropbox which allows me to print from a smartphone by dropping files into Dropbox.... neat!
I used a POGO printer in my case, here is the bash code with embedded Applescript at the end:
################################################################################
# POGOprint
# Send image supplied as parameter to Polaroid POGO printer using Bluetooth
# File Exchange
#
# Mark Setchell
################################################################################
# User editable parameters - get address by clicking Bluetooth icon at top-right
# of the Mac screen and looking for the POGO
# Install ImageMagick using "homebrew", with:
# brew install imagemagick
pogo_address="00-04-48-13-9f-64"
tmp="/tmp/POGO.jpg"
# Get width and height of image using ImageMagick
read w h < <(convert "$1" -format "%w %h" info: )
if [ $w -gt $h ]; then
# Landscape format - wider than tall
convert "$1" -resize 900x600 $tmp
else
# Portrait format - taller than wide
convert "$1" -resize 600x900 $tmp
fi
osascript<<EOF
with timeout of 60 seconds
tell application "Bluetooth File Exchange"
send file "$tmp" as string to device "$pogo_address"
end tell
end timeout
EOF
Is there any way to display the CFBundleShortVersionString as a UILabel text in my LaunchStoryboard without entering it by hand every time it increments? I know how to do it in code, but it is not possible to run code while the LaunchStoryboard is shown.
Is it possible through Xcode variables?
As we all know, you can't put code in a launch screen. And unfortunately there isn't a built-in way to use a variable for a label's text in the launch screen (similar to how you can preprocess Info.plist with values in a header file).
The only option available to achieve your goal would be to write your own script that updates the LaunchScreen.storyboard file and add that script as a custom Build Phase for your target.
To make this easier, I would setup your target to use a preprocessor file for Info.plist. Once that is done and working, you now have a separate and simple header file you can interrogate in your script to process the LaunchScreen.storyboard file.
Here's a complete solution:
Create a file named Info.h and add it to the root of your project.
Add the following line:
#define APP_VERSION 2.6 // Update this version as needed
Now select your project's target in Xcode and go to the General tab. Change the Version value from whatever number you have there to APP_VERSION.
Now select the Build Settings tab. Search on Info. Under the Packaging section, set the Preprocess Info.plist File to Yes. Also set the Info.plist preprocessing Prefix File to Info.h.
Now when you do a build, the CFBundleShortVersionString value in Info.plist will be set to the value in the Info.h file.
To get the label in the launch screen file updated to match, do the following:
Select your launch screen storyboard and then select the label that will contain the version number. Show the Identity Inspector pane. Enter APP_VERSION into the Label attribute. If you look at the storyboard file now, the XML for the label will now show a userLabel attribute with the value of APP_VERSION.
Go back to the project target and select the Build Phases tab. Click the + icon and choose to add a New Run Script Phase. Rename the new phase to something useful like "Update Launch Version". Then drag the new phase to before the existing "Copy Bundle Resources" phase.
Now open the new "Update Launch Version" phase. Enter /bin/bash in the Shell field. Copy and paste the following code into the phase:
VERSION=`cat Info.h | grep APP_VERSION | cut -f3 -d' '`
sed -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$VERSION\"/" Storyboard.storyboard > tmp.storyboard
Now do a clean build. This is a test at this point. Have a look at tmp.storyboard and make sure it looks correct and the label for the app version is showing the proper version.
Once that is working, update the above code to:
VERSION=`cat Info.h | grep APP_VERSION | cut -f3 -d' '`
sed -i bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$VERSION\"/" Storyboard.storyboard
This final version actually updates the launch screen storyboard file. The previous version was a test to make sure everything else was working without risk to trashing your storyboard.
I figured out the script to update the Version & Build label on LaunchScreen.storyboard based on the first answer without using any extra files. Unfortunately, Clemens Brockschmidt's solution doesn't work due to some Syntax errors and incorrect paths.
Make sure to name your label to "APP_VERSION" in Identity Inspector pane -> Document -> Label.
Also create your script before "Copy Bundle Resources" phase.
UPDATE: My older answer didn't work in the newest Xcode environment. I've fixed the current issues and refactored the script.
And here's the final working script with shell: /bin/sh in XCode 11 (Swift 5):
# ON/OFF Script Toggle (script ON with #, script OFF without #)
#exit 0
# Increment Build Number Bool (Increment ON with true, increment OFF with false)
shouldIncrement=false
# App vesion / Build version constants
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/Base.lproj/LaunchScreen.storyboard"
versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"
# Increment build number
if [ "$shouldIncrement" = true ]; then
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi
# Output version & build numbers into a label on LaunchScreen.storyboard
sed -i .bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$versionNumber($buildNumber)\"/" "$sourceFilePath"
As a BONUS I've included a build number incrementer and ON/OFF script toggle to disable your incrementer when you build your project a lot. Let me know if you have any issues or if this works for you.
Edit
There is no way to make the launch screen dynamic. Doesn't work good
with localizations too etc
A alternative is given below
Previous Answer
You should make your inital VC similar to the LaunchScreen.xib and in that make a label.
Now in the ViewController you can access the info plist through NSBundle method and set its value. This would make the transition from Launch screen to first VC smooth and look natural with version code animating in or something if you want
let appVersion = NSBundle.mainBundle().infoDictionary["CFBundleVersion"];
myLabel.text = "\(appVersion)"
I have a project with multiple targets. Assume the targets are named Target-A, Target-B and so on. For every target I have a different asset catalog of App Icons. They are named as AppIcon - A, AppIcon - B and it goes on for all the targets. I have assigned respective asset catalogs to all targets, but it only shows the icons for Target-A when i run on the device / simulator. For all other targets it does not set any icons and shows iOS 7 default placeholder icon.
Please help!
If you're using PODs in your project, then you have to edit "Pods-resources.sh" and remove "xcassets" commands (see attached picture).
When you are adding the app icon image please note while adding app icon-1 to Test target then select only test target not Test copy target same for Test copy target.
Also add row for "Icon file" in both the plist and specify your app icon names.
Please check following screen shots you will get some ideas.
The easiest way for me was to add multiple "App Icon" in the same xcassets file. With this technique, I had no problem with Cocoapod :
Open your xcassets file
Right click on the left column
Click "New App icon"
Then you can easily select the correct "App Icon" for each target.
So I wrote a script to delete all those lines which are pointed out by Lukapple.Paste the code to run Script in the xcode project after Target Dependencies.
echo "run script to remove Pods-resources.sh"
file_name="${PROJECT_DIR}/Pods/Target Support Files/Pods/Pods-resources.sh"
function remove_wrapper_extensions {cat "$1" | awk 'BEGIN { suppress_output = 0; } /^if \[\[ -n/ { suppress_output = 1; } (!suppress_output) { print $0; } /^fi$/ { suppress_output = 0; }' > "${1}.1"}
function remove_case_statement {cat "$1" | awk 'BEGIN { suppress_output = 0; } /\s*\*\.xcassets\)$/ { suppress_output = 1; } (!suppress_output) { print $0; } /;;/ && (suppress_output) { suppress_output = 0; }' > "${1}.2"}
remove_wrapper_extensions "$file_name"
remove_case_statement "${file_name}.1"
rm "${file_name}"
rm "${file_name}.1"
mv "${file_name}.1.2" "$file_name"
chmod +x "${file_name}"
Anyone know a good solution?
So far I have not found a better way than using File>New file and then copying contents from old file to new.
You can probably duplicate in Finder and re-import but that's almost same amount of work: switching to finder, duplicate, import new files.
Doing this with one class is not so hard, but what to do if you need to generate 10+ similar Classes based on superclass.
In Eclipse you select file and then copy/paste it in same folder. In finder there's Duplicate.
There's a menu Edit > Duplicate. But it's ALWAYS disabled. I tried selecting various files, classes, methods. It's still disabled.
In XCode 4.2 (I know this is an old question) there is Duplicate under the File menu.
Select the file (you can select multiple files but it doesn't appear to do anything useful) in the Project Navigator and then File->Duplicate. Hooray!
In Xcode 4.5 we can duplicate using File-> Duplicate or cmd + shift + S
"Duplicate" is enabled for targets in XCode (pretty much nothing else that I know of).
If you have a substantial number of subclasses with the same starting point to replicate, why not make a class template from it? Then you can just use file->New to make new instances. It's fairly quick to do.
This is probably the simplest example:
http://www.macresearch.org/custom_xcode_templates
Otherwise, I'd simply duplicate the files in Finder as many times as you need, name them, and drag them into XCode en-masse.
Careful!
When you use duplicate ( CMD + Shift + S ) - Xcode have a problem with indexing headers.
Also when u want to make a refactoring it can be next error window:
So there a couple of ways what to do, to fix that.
Delete derived data from menu Window > Projects. Restart Xcode.
Product > Clean
You could use "Save As..."; you'd still have to go back and re-add the original files to the project, though.
It wouldn't be such a bad way to do a bunch of related classes, though: edit file, Save As "class2", edit file, Save As "class3", etc., then "Add Existing Files" and re-add all of the files but the last to your project.
I use the following perl script to duplicate a file pair in the Terminal. You give it the base name of the original and new file, and it copies the header and implementation (c/cpp/m/mm) file, then replaces all occurances of the base name with the new name, then adds them to subversion. You still have to add the new files in to Xcode and adjust the creation date in the comment (I've got a Keyboard Maestro macro for that), but its quicker than doing a lot of the steps manually. I operate with a Terminal window and four tabs pre-set to the Project, Source, Resources, and English.lproj directory which gives quick access for a lot of operations.
#!/usr/bin/perl
use lib "$ENV{HOME}/perl";
use warnings;
use strict;
our $cp = '/bin/cp';
our $svn = '/usr/bin/svn';
our $perl = '/usr/bin/perl';
our $source = shift;
our $add = 1;
if ( $source =~ m!^-! ) {
if ( $source eq '-a' || $source eq '--add' ) {
$add = 1;
$source = shift;
} elsif ( $source eq '-A' || $source eq '--noadd' ) {
$add = undef;
$source = shift;
} else {
die "Bad arg $source";
}
}
our $dest = shift;
die "Bad source $source" unless $source =~ m!^(.*/)?[A-Za-z0-9]+$!;
die "Bad dest $dest" unless $dest =~ m!^(.*/)?[A-Za-z0-9]+$!;
my $cpp;
$cpp = 'c' if ( -e "$source.c" );
$cpp = 'cpp' if ( -e "$source.cpp" );
$cpp = 'mm' if ( -e "$source.mm" );
$cpp = 'm' if ( -e "$source.m" );
die "Missing source $source" unless -e "$source.h" && -e "$source.$cpp";
die "Existing dest $dest" if -e "$dest.h" && -e "$dest.$cpp";
our $sourcename = $source; $sourcename =~ s!.*/!!;
our $destname = $dest; $destname =~ s!.*/!!;
print "cp $source.h $dest.h\n";
system( $cp, "$source.h", "$dest.h" );
print "s/$sourcename/$destname in $dest.h\n";
system( $perl, '-p', '-i', '-e', "s/$sourcename/$destname/g", "$dest.h" );
print "cp $source.$cpp $dest.$cpp\n";
system( $cp, "$source.$cpp", "$dest.$cpp" );
print "s/$sourcename/$destname in $dest.$cpp\n";
system( $perl, '-p', '-i', '-e', "s/$sourcename/$destname/g", "$dest.$cpp" );
if ( $add ) {
print "svn add $dest.$cpp $dest.h\n";
system( $svn, 'add', "$dest.$cpp", "$dest.h" );
}
In my case, one of my folder changed from one place to another place.
I have "Home" folder in Controller folder, but unfortunately it's moved from Controller folder to Manager folder.
I checked many times everything fine, but I'm getting Command PrecompileSwiftBridgingHeader failed with a nonzero exit code
But after 2 hours i realised, my folder structure changed.