• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips

Mac

How to set preferred Wifi network on Mac

November 16, 2021 By Ravi Shankar

This tutorial provides the steps for making a specified WiFi network as a preferred network on Mac. This is quite useful when you have multiple Wi-Fi networks at your work place or home and you want to set a preferred order.

  • Click the WiFi option on the Menu bar and select Network Preferences from the menu list. You can also access the Network Preferences via System Preferences.

  • In the Network Preferences, click the Advanced option available at the bottom of the screen.
  • Now you can set preferred order by dragging and dropping the network.

    Filed Under: Mac, Tips Tagged With: network, Wifi

    How to recover Firefox password from Time Machine backup

    November 7, 2021 By Ravi Shankar

    Here are steps to recover Firefox passwords from Time Machine backup on Mac.

    1. Open Time Machine and navigate to the backup data from which you want to retrieve the Firefox passwords
    2. Make sure hidden files and folders option is enabled on your Mac.
    3. Navigate to Users -> <UserName> -> Library
    4. Under Library navigate to Application Support followed Firefox folder.
    5. Under Firefox navigate to Profiles and open the folder ending with default-release.
    6. Copy key4.db and logins.json.
    7. Copy the above two files to Profiles folder under Users/<UserName>/Library/Application Support/Firefox/…default-release/Profiles. Before copying make sure to take a backup of existing key4.db and logins.json files.

    Now all your saved usernames and passwords for Firefox will be available on your Mac.

    Filed Under: Firefox, Mac, Tips Tagged With: recover passwords

    Show hidden files and folders on Mac

    November 6, 2021 By Ravi Shankar

    Hidden files and folders are by default not shown on your Mac. Here are the different ways you can show hidden files and folders.

    Terminal

    1. Open Terminal and run this script, defaults write com.apple.Finder AppleShowAllFiles true
    2. Make sure to close all finder windows and relaunch Finder –  killall Finder

    And if you want turn off this option this change true to false, defaults write com.apple.Finder AppleShowAllFiles false

    Keyboard Shortcut

    Navigate to the folder you want to see the hidden files and folders and type “Cmd + Shift + .“. And to turn off press the same keyboard combination again.

    Finder

    If you want to see the hidden library folder then follow the given steps.

    1. Open Finder and navigate to Go menu bar
    2. Navigate to Go to Folder and type  ~/Library (Keyboard shortcut in Cmd + Shift + G)

    Filed Under: Mac, Tips Tagged With: Hidden files, Hidden Folders

    Turn on/off Wifi using Keyboard shortcut

    June 6, 2021 By Ravi Shankar

    Mac users can turn on/off Wifi using option available as part of the Menu bar.

    Wifi Menu bar option

    Add quick action in Automator app

    Launch Automator app on your mac and choose Quick Action.

    Automator – Quick Action

    Choose action as “Run Shell Script” then set Workflow receives to “no input” and set it to run for for any application and select an image for your action.

    Then under the run script window add the following script.

    set_wifi_on_or_off() {
      networksetup -getairportpower en${n} | grep ": ${1}";
      if test $? -eq 0;
      then
        echo WiFi interface found: en${n};
        eval "networksetup -setairportpower en${n} ${2}"
        return 0;
      fi
      return 1;
    }
    
    for n in $(seq 0 10);
    do
      if set_wifi_on_or_off "On" "off"; then break; fi;
      if set_wifi_on_or_off "Off" "on"; then break; fi;
    done

    You can test the above script using “Run” option and check if Wifi settings turned On or Off based on the current state. Save this quick action by providing a name as “Wifi”

    Assign a keyboard shortcut for quick action

    Launch Keyboard preferences using System preferences and navigate to Shortcuts tab.

    Keyboard Preferences

    The newly added Wifi quick action will be available under Services. Now assign a keyboard shortcut for this action.

    Note :- Make sure to select 3 letters or more keyboard combination for your shortcut. Sometimes other apps might be using the same set of key combination and this would prevent launching the Automator action.

    References

    Filed Under: Automator, Mac, Tips Tagged With: Automator, Keyboard Shortcut, Mac

    How to know the size of the folders in iCloud

    February 15, 2021 By Ravi Shankar

    If you are using Apple iCloud, the folder sizes are not shown by default when they are not downloaded to your Mac. Doing the following will show all the folder size whether they are downloaded or present only in iCloud.

    1. Using Finder, Access the iCloud drive.
    2. Navigate to folder in iCloud drive. As you can see in the below screenshot the folders size are not shown as they available in Cloud.
    1. Click View menu option and select “Show View Options” from the menu list.
    1. Tick the checbox with the label “Calculate all sizes”

    Now the Finder should show all the folder size even if they are present in Cloud only.

    Filed Under: Mac Tagged With: iCloud, Mac

    Errors were encountered while preparing your device

    February 14, 2021 By Ravi Shankar

    One of the common error that occurs in Xcode is “Error were encounted while preparing your device for development. Please check the Devices and Simulators Window.” I have noticed this error after Mac OS update or Xcode app update Trying the following

    1. Restart your device,
    2. Close Xcode and try re-running the Xcode project.

    Sometimes after restarting the device you might see the following “iPhone is Busy: Making iPhone ready for development”. Give some time for the device after a restart, this might fix the problem.

    If you have come across these during any other scenarios, please share them in the comments section. Thank you.

    Filed Under: iPhone, Mac, Xcode Tagged With: Mac, Mac OS

    Add line numbers in Word 2013, Word 2010 and Word 2007

    September 27, 2015 By Ravi Shankar Leave a Comment

    Microsoft Word users can add line numbers to a word document using the options available as part of Page Layout menu. In this tutorial we will see the steps for adding line number in Word 2013 and Word 2011 for Mac.

    How to add line numbers in Word 2007, Word 2010, Word 2013 and Word 2011 for Mac

    Word 2007 Word 2010 and Word 2013

    Word 2010 allows users to add line numbers to a word document. This can be done using the Page Layout menu option. For example if you have the following text in your document and you want insert line numbers for each line then you use this feature.

    image

    To add line numbers for above paragraph, from Home menu click the Page Layout menu option and then navigate to Page Setup section.

    Page Layout Menu in Word 2013 and Word 2010

    In the Page Layout section, click the drop down arrow next to Line Numbers menu option. This would display the following menu options.

    Line numbers in Word 2013 and Word 2010

    Now select Continuous from the list available menus and this would insert the line numbers in the Word document as shown below

    Document with line numbers in Word 2010 and Word 2013

    The other line numbers options includes

    • Restart Each Page – To restart line numbers after each page.
    • Restart Each Section – To restart line numbers after each section.
    • Suppress for Current Paragraph – to remove line numbers for the selected paragraph.

    Word 2011 for Mac

    Step 1: Open the document for which you want to add line number.

    Word 2011 for Mac Layout Menu

    Step 2: Click Layout menu and navigate to Text Layout section.

    Step 3: Now click the Line Numbers option under Text Layout. This should display the following drop down list.

    Word 2011 for Mac Continuous numbers

    Step 4: Select Continuous from the Line numbers drop down list to add line numbers. You can also customise Line numbers by use other options in the list.

    Show line numbers in document

    If you are looking for advanced line number options then click More Line Numbering.

    More line numbers option

    Display of line number in status bar

    If you just want to find out the current line number while editing a document then you can use line number option available as part of status bar for this purpose.

    Word 2007, Word 2010 and Word 2013

    Microsoft Word 2007 and Word 2010 provides option to display the line numbers in a word document. This would be a useful feature when you want to restrict your content based on the number of lines written in the document. If the status bar does not show the line numbers, then right click on the Status bar and select Line number.

    Display line number in status bar in Word 2013, Word 2010 and Word 2007

    After selecting Line Number option in the Customize Status Bar context menu, the status bar would display the line number as shown below.

    Show line numbers in Word status bar

    Word 2011 for Mac

    Word 2011 for Mac does not support the display of line number in status bar. This option is available in Window’s version of Microsoft Word but not in Mac OS X.

    Also See: How to auto populate random sentences in Word 2010

    Filed Under: Apple, Mac, MS Office, Office 2010, Office 2013, Word 2007, Word 2010, Word 2013 Tagged With: Apple, Line numbers, Mac, Page Layout, Show Line numbers, Status Bar, Word 2011 for Mac

    Swift – Beginners Tutorial

    May 8, 2015 By Ravi Shankar Leave a Comment

    Swift is the latest programming language released by Apple for developing OS X and iOS apps.

    • Best of C and Objective-C
    • Adopts safe programming patterns and modern features
    • Supports Playground, a tool for seeing the result immediately.
    • Provides access to Cocoa libraries and can work in conjunction with Objective-C
    • Combines Procedural and Object-Oriented programming.
    • No need to use semicolon at the end of statement. Use it only when you have more than one statement in single line.
    • Swift uses var and let. only mutable variable needs var.
    • Swift uses type inference.
    • Supports unicode characters. You can use any character as variable.
    • Prefer usage of constant (let) for immutable than using var.
    • Optional variables can contain value or nil. – var givenName : String? = “Ravi”
    • Swift’s Switch supports all kinds of datatype and operations and does not need a break statement after each case statement.
    • No need to enclose your expression in brackets with if statements
    • Swift function supports default value for the parameter and variable parameter.
    • Closures are like blocks in Objective-C ( ) -> ( )
    • No need to specify header file in Swift
    • No need to specify base class and there is no universal base class
    • No difference between instance variable and properties
    • Tuples – Grouping of multiple values.
    • Nested multiline comments are allowed.
    • Use typealias to provide different name to an existing type.
    • Swift nil represents absence of value and objective – C nil represents pointer to a non-existent object.
    • Implicitly unwrapped optional let pincode : String! = “E151EH”
    • Provides Assertion to end code execution where certain criteria is not met.
    • Swift’s String is value type and not passed by reference.
    • Supports Optional Binding and Optional Chaining

    Variables and Constants

    [code language=”swift”]
    // Variables and Constants

    var myStr = "Swift"
    var myValue = 23.1 //(Implicit variable declaration or type inference)
    var myDoubleValue: Double = 23 //(Explicit variable declaration)

    // let

    let myAge = 38
    let message = "My age is " + String(myAge) //(Converting value to a String)
    let newMessage = "My age is \(myAge)" //(Converting value to a String using backslash or interpolation)

    [/code]

    Data types in Swift

    • String
    • Int (Range -2,147,483,648 to 2,147,483,648)
    • Double (15 digit precision)
    • Float (6 digit precision)
    • Bool

    Fun with String

    [code language=”swift”]// String
    var movie:String = "Independence Day "
    count(movie) // count of string

    // Use NSString to format a double or float value
    var range = NSString(format: "%.2f", 24.5)

    // Concatenate String values
    movie += String(range)[/code]

     

    Collection Types

    Array

    [code language=”swift”]// Declarations
    // var fruits = ["Orange", "Apple", "Grapes"] – Short declartion
    // var fruits:Array = ["Orange", "Apple", "Grapes"] – Long declaration
    // var fruits:[String] = [] – Assign empty array

    var fruits:[String] = ["Orange", "Apple", "Grapes"] // short declaration with type.

    // insert item at index
    fruits.insert("Mangoes", atIndex: 2)

    // append item to the last
    fruits.append("Pine Apple")

    // count of array
    fruits.count

    // remove item
    fruits.removeAtIndex(1)

    // sort array elements
    fruits.sort { (a, b) -&gt; Bool in
    a &lt; b
    }

    // retrieve index using find
    find(fruits, "Mangoes")
    [/code]

    Dictionary

    [code language=”swift”]// Dicionary

    // Declaration

    // var employees = [1:"John",2:"Peter",3:"David"] // Short form

    // var employees:Dictionary = [1:"John",2:"Peter",3:"David"] // Long form

    // var employees:[Int:String] = Dictionary() // Empty dictionary

    var employees:[Int:String] = [1:"John",2:"Peter",3:"David"] //Short form with type

    // Add new item to dictionary

    employees[4] = "Bob"

    // Remove an item using key

    employees.removeValueForKey(3)
    [/code]

    Assignment Operator

    • a = b
    • let (a,b) = (2,3) – supports tuple.
    • Does not return value.

    Arithmetic Operators

    • Addition (+), Subtraction (-), Multiplication (*), Division (/)
    • + can be used for string concatenation.
    • % – Returns remainder for both +ve and -ve numbers. Also returns remainder for floating point numbers.
    • Increment and Decrement operators, ++i (i = i + 1), —i (i = i – 1).
    • Supports i++ and i— (increments or decrements after returning the value).
    • Unary Minus and Unary Plus

    Compound AssignmentOperator

    • x += 2 is same as x = x + 2.

    ComparisonOperators

    • x == y
    • x != y
    • x > y
    • x < y
    • x >= y
    • x <= y
    • === and !== used for testing object references.

    Ternary Conditional Operator

    • a = flag ? 10 : 20 (if flag is true then a will updated to 10 and 20 incase it is false).

    RangeOperators

    • Closed Range – e.g.:- 1…10, has three dots and includes values from 1 to 10.
    • Half Closed – e.g.:- 1..10, has two dots and includes values from 1 to 9

    LogicalOperators

    • NOT ( !x )
    • AND ( x && y )
    • OR ( x || y )

    Control Flow

    [code language=”swift”]// Control flow

    // if else
    if fruits[0] == "Grapes" {
    println("for breakfast")
    } else if fruits[0] == "Apple" {
    println("for lunch")
    } else {
    println("Nothing")
    }

    // for statements
    // exclusive range

    for index in 0..<h3><u>Comments</u></h3>[code language="swift"] Single line comments // examples
    Multiline comments /* example1
    example2 */

    [/code]

    Function

    [code language=”swift”]func sum(number1:Int, number2: Int) -&gt; (Int) {
    return number1 + number2
    }[/code]

    The above function is an example of multiple input parameters. It does the addition of two numbers where number1 and number are arguments of type Int and it returns a value of type int. And a function without parameter looks like this.

    [code language=”swift”]
    func sum() -&gt; (Int) {
    return 10 + 5
    }[/code]

    The above function is an example of multiple input parameters. It does the addition of two numbers. number1 and number are arguments of type Int and it returns a value of type int. And a function without parameter looks like this. Swift function can also have multiple return values.


    Define external parameter name

    [code language=”swift”]func sum(addNumber1 number1:Int, withNumber2 number2: Int) -&gt; (Int) {
    return number1 + number2
    }

    println(sum(addNumber1: 10, withNumber2: 20))
    [/code]

     

    addNumber1 and withNumber are external parameter names for two parameters. And you use # to tell local and external parameter name are same.

    [code language=”swift”]
    func sum(#number1:Int, #withNumber2: Int) -&gt; (Int) {
    return number1 + withNumber2
    }
    println(sum(number1: 10, withNumber2: 20))[/code]

    Function with default parameter value

    [code language=”swift”]func sum(number1:Int, withNumber2: Int = 20) -&gt; (Int) {
    return number1 + withNumber2
    }
    println(sum(10))[/code]

    The above function has default value for the second parameter.

    Variadic Parameters

     

    A function with variadic parameters can accept zero or more values. Maximum of one parameter is allowed in a function and it is always last in the list.

    [code language=”swift”]
    // Variadic parameters
    func totalSum(numbers:Int…) -&gt; Int {
    var sum = 0
    for number in numbers {
    sum += number
    }
    return sum
    }
    totalSum(1,2,3,4,5)[/code]

    Variable and inout parameters

    Variable parameters in a function are indicated by var keyword and the scope is available only within the function. If you want to access the modified variable value outside the function then you specify them as inout parameter. And prefix with & while passing the parameter in the function call.

    [code language=”swift”]
    // inout parameters
    var employee = "Ravi"

    func greetings(inout employee:String) {
    employee += "!"
    }
    println(greetings(&amp;employee))
    println(&amp;employee)[/code]

    Filed Under: Apple, ios, Mac Tagged With: Apple, Quick Reference, Swift

    1. Pages:
    2. 1
    3. 2
    4. 3
    5. »
    Next Page »

    Primary Sidebar

    TwitterLinkedin

    Recent Posts

    • How to set preferred Wifi network on Mac
    • Attribute Unavailable: Estimated section warning before iOS 11.0
    • How to recover Firefox password from Time Machine backup
    • Show hidden files and folders on Mac
    • How to request a refund for apps in App Store

    Pages

    • About
    • Privacy Policy
    • Terms and Conditions

    Copyright 2022 © rshankar.com

    Terms and Conditions - Privacy Policy