The UK is still a member of the EU.
If Scotland were to start negotiations now to remain in the UK when the UK leaves they would inevitably need agreement by all states of the EU. Including the UK - which would still be a member. The EU don't agree this kind of thing on a majority vote alone (see below - universality is the rule and each individual national parliament has to agree as well as EU bodies) The Scottish Gov. would have to first get the agreement of the people of Scotland. I see no moves in that direction. I think we can assume that Scotland will be out, along with the rest of us, in spring 2019.
After the UK leaves Scotland could apply to join via the process below. But they'd have a bit of a problem. They'd first have to declare independence, so that they could apply as a country in their own right. This would be a long, slow process. And their admittance would be dependent on their track record as an economy. A track record that they would not have. We're talking a few decades here, minimum, before they would get a yes/no answer. Turkey have been tin the joining process for 30 years and they would not have Scotland's disadvantages.
If Catalonia leaves and wishes to retain membership, again the principle of universality would prevail. And that is where other countries would put their collective and sovereign feet right down. Spain, still an EU member, would, without a doubt block it, because they would not other regions of Spain doing likewise. And why would several others, with their own regional independence movements, do otherwise?
Where there is a will there is not always a way if you have powerful entities who can quite legally block your way and would certainly wish to do so. No amount of wishful thinking would make a scrap of difference.
It's the same with the UK leaving "deal" if we ever get one on the table. Each individual national parliament will have to agree to it.
This is the process for joining the EU in a (rather large) nutshell:
A country that wishes to join the EU addresses its application to the Council, which asks the Commission to submit an opinion. The European Parliament is notified of this application. If the Commission’s opinion is favourable, the European Council may decide — by unanimity — to grant the country candidate status. Following a recommendation by the Commission the Council decides — by unanimity — whether negotiations should be opened. The sum of EU legislation (the acquis communautaire) is divided into more than 30 policy chapters. Before actual negotiations start, the Commission delivers a ‘screening’ report for each chapter. On the basis of the Commission’s recommendation, the Council decides by unanimity whether or not to open each new negotiation chapter. Whenever progress is judged satisfactory, the Commission may recommend ‘provisionally closing’ a chapter. The Council again decides by unanimity. When negotiations on all the chapters are completed, the terms and conditions — including possible safeguard clauses and transitional arrangements — are incorporated into an accession treaty between the EU Member States and the candidate state. Only after Parliament’s consent and the Council’s unanimous approval can the accession treaty be signed. It is then submitted by all contracting states for ratification, in accordance with their constitutional requirements (i.e. ratification by parliament or referendum).